summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
Diffstat (limited to 'Presence')
-rw-r--r--Presence/FGConsole.hs2
-rw-r--r--Presence/LocalPeerCred.hs2
-rw-r--r--Presence/ServerC.hs9
-rw-r--r--Presence/XMLToByteStrings.hs4
-rw-r--r--Presence/XMPP.hs110
-rw-r--r--Presence/main.hs59
6 files changed, 93 insertions, 93 deletions
diff --git a/Presence/FGConsole.hs b/Presence/FGConsole.hs
index c72addff..6686e19f 100644
--- a/Presence/FGConsole.hs
+++ b/Presence/FGConsole.hs
@@ -14,7 +14,7 @@ import Control.Monad
14import Foreign.C.Error 14import Foreign.C.Error
15import Foreign.C 15import Foreign.C
16 16
17import Debug.Trace 17import Logging
18import System.Posix.Signals 18import System.Posix.Signals
19 19
20-- c_monitorTTY fd = trace "c_monitorTTY" (return ()) -- (trace "WTF" todo) 20-- c_monitorTTY fd = trace "c_monitorTTY" (return ()) -- (trace "WTF" todo)
diff --git a/Presence/LocalPeerCred.hs b/Presence/LocalPeerCred.hs
index f66421f8..e5832b47 100644
--- a/Presence/LocalPeerCred.hs
+++ b/Presence/LocalPeerCred.hs
@@ -17,7 +17,7 @@ import Data.Binary
17import Data.Bits 17import Data.Bits
18import System.Posix.Types 18import System.Posix.Types
19import System.Posix.Files 19import System.Posix.Files
20import Debug.Trace 20import Logging
21import SocketLike 21import SocketLike
22import ControlMaybe 22import ControlMaybe
23 23
diff --git a/Presence/ServerC.hs b/Presence/ServerC.hs
index 02c6446e..d8cca897 100644
--- a/Presence/ServerC.hs
+++ b/Presence/ServerC.hs
@@ -12,8 +12,7 @@ module ServerC
12 ) where 12 ) where
13 13
14import Network.Socket as Socket 14import Network.Socket as Socket
15import Data.ByteString.Lazy.Char8 as L 15import Logging
16 ( putStrLn )
17import Data.ByteString.Char8 16import Data.ByteString.Char8
18 ( hGetNonBlocking 17 ( hGetNonBlocking
19 ) 18 )
@@ -97,10 +96,10 @@ doServer (HCons family port) g = runServer port (runConn g)
97 "resource exhausted" -> return Retry 96 "resource exhausted" -> return Retry
98 97
99 -- InvalidArgument 98 -- InvalidArgument
100 "invalid argument" -> L.putStrLn "quit accept-loop." >> return QuitOnException 99 "invalid argument" -> debugL "quit accept-loop." >> return QuitOnException
101 100
102 _ -> do 101 _ -> do
103 L.putStrLn ("accept-loop exception: " <++> bshow ioerror <++> "\n") 102 debugL ("accept-loop exception: " <++> bshow ioerror <++> "\n")
104 return QuitOnException 103 return QuitOnException
105 104
106 mcon <- handle doException $ fix $ \loop -> do 105 mcon <- handle doException $ fix $ \loop -> do
@@ -146,6 +145,6 @@ runConn ::
146runConn g st (sock,_) = do 145runConn g st (sock,_) = do
147 h <- socketToHandle sock ReadWriteMode 146 h <- socketToHandle sock ReadWriteMode
148 hSetBuffering h NoBuffering 147 hSetBuffering h NoBuffering
149 let doException (SomeException e) = Prelude.putStrLn ("\n\nexception: " ++ show e ++ "\n\n") 148 let doException (SomeException e) = debugStr ("\n\nexception: " ++ show e ++ "\n\n")
150 handle doException (g (restrictSocket sock `HCons` st) (packets h) (packetSink h)) 149 handle doException (g (restrictSocket sock `HCons` st) (packets h) (packetSink h))
151 hClose h 150 hClose h
diff --git a/Presence/XMLToByteStrings.hs b/Presence/XMLToByteStrings.hs
index 92ac05cd..b15ab34a 100644
--- a/Presence/XMLToByteStrings.hs
+++ b/Presence/XMLToByteStrings.hs
@@ -13,7 +13,7 @@ import qualified Data.Conduit.List as CL
13import qualified Data.Conduit.Binary as CB 13import qualified Data.Conduit.Binary as CB
14import Data.XML.Types as XML (Event) 14import Data.XML.Types as XML (Event)
15import qualified Data.ByteString as S (ByteString,append) 15import qualified Data.ByteString as S (ByteString,append)
16import qualified Data.ByteString.Char8 as S (putStrLn) 16import Logging
17#ifdef RENDERFLUSH 17#ifdef RENDERFLUSH
18import Data.Conduit.Blaze (builderToByteStringFlush) 18import Data.Conduit.Blaze (builderToByteStringFlush)
19import Text.XML.Stream.Render (def,renderBuilderFlush,renderBytes,rsPretty) 19import Text.XML.Stream.Render (def,renderBuilderFlush,renderBytes,rsPretty)
@@ -69,4 +69,4 @@ renderChunks = fixMaybeT $ \loop -> do
69 69
70prettyPrint prefix xs = 70prettyPrint prefix xs =
71 liftIO $ do 71 liftIO $ do
72 CL.sourceList xs $= renderBytes (def { rsPretty=True }) =$= CB.lines $$ CL.mapM_ (S.putStrLn . (prefix `S.append`)) 72 CL.sourceList xs $= renderBytes (def { rsPretty=True }) =$= CB.lines $$ CL.mapM_ (debugS . (prefix `S.append`))
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index 378c6785..6dbc64b0 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -23,6 +23,7 @@ import ByteStringOperators
23import ControlMaybe 23import ControlMaybe
24import XMLToByteStrings 24import XMLToByteStrings
25import SendMessage 25import SendMessage
26import Logging
26 27
27import Data.Maybe (catMaybes) 28import Data.Maybe (catMaybes)
28import Data.HList 29import Data.HList
@@ -31,8 +32,7 @@ import Control.Concurrent.STM
31import Data.Conduit 32import Data.Conduit
32import Data.ByteString (ByteString) 33import Data.ByteString (ByteString)
33import qualified Data.ByteString.Lazy.Char8 as L 34import qualified Data.ByteString.Lazy.Char8 as L
34 ( putStrLn 35 ( fromChunks
35 , fromChunks
36 ) 36 )
37import Control.Concurrent.Async 37import Control.Concurrent.Async
38import Control.Exception as E ( finally ) 38import Control.Exception as E ( finally )
@@ -187,7 +187,7 @@ handleIQSetBind session cmdChan stanza_id = do
187 rsc <- case mchild of 187 rsc <- case mchild of
188 Just child -> do 188 Just child -> do
189 let unhandledBind = do 189 let unhandledBind = do
190 liftIO $ putStrLn $ "unhandled-bind: "++show child 190 liftIO $ debugStr $ "unhandled-bind: "++show child
191 return "" 191 return ""
192 case tagName child of 192 case tagName child of
193 "{urn:ietf:params:xml:ns:xmpp-bind}resource" 193 "{urn:ietf:params:xml:ns:xmpp-bind}resource"
@@ -196,10 +196,10 @@ handleIQSetBind session cmdChan stanza_id = do
196 return . textToByteString $ rsc 196 return . textToByteString $ rsc
197 _ -> unhandledBind 197 _ -> unhandledBind
198 Nothing -> do 198 Nothing -> do
199 liftIO $ putStrLn $ "empty bind request!" 199 liftIO $ debugStr $ "empty bind request!"
200 return "" 200 return ""
201 liftIO $ do 201 liftIO $ do
202 L.putStrLn $ "iq-set-bind-resource " <++> rsc 202 debugL $ "iq-set-bind-resource " <++> rsc
203 setResource session rsc 203 setResource session rsc
204 jid <- getJID session 204 jid <- getJID session
205 atomically $ do 205 atomically $ do
@@ -229,7 +229,7 @@ handleIQSetSession session cmdChan stanza_id = do
229handleIQSet session cmdChan tag = do 229handleIQSet session cmdChan tag = do
230 withJust (lookupAttrib "id" (tagAttrs tag)) $ \stanza_id -> do 230 withJust (lookupAttrib "id" (tagAttrs tag)) $ \stanza_id -> do
231 whenJust nextElement $ \child -> do 231 whenJust nextElement $ \child -> do
232 let unhandledSet = liftIO $ putStrLn ("iq-set: "++show (stanza_id,child)) 232 let unhandledSet = liftIO $ debugStr ("iq-set: "++show (stanza_id,child))
233 case tagName child of 233 case tagName child of
234 "{urn:ietf:params:xml:ns:xmpp-bind}bind" 234 "{urn:ietf:params:xml:ns:xmpp-bind}bind"
235 -> handleIQSetBind session cmdChan stanza_id 235 -> handleIQSetBind session cmdChan stanza_id
@@ -329,10 +329,10 @@ handleIQGet session cmdChan tag = do
329 names <- getNamesForPeer (peer jid) 329 names <- getNamesForPeer (peer jid)
330 return (S.decodeUtf8 . head $ names) 330 return (S.decodeUtf8 . head $ names)
331 let unhandledGet req = do 331 let unhandledGet req = do
332 liftIO $ putStrLn ("iq-get: "++show (stanza_id,child)) 332 liftIO $ debugStr ("iq-get: "++show (stanza_id,child))
333 liftIO . atomically . writeTChan cmdChan . Send $ iq_service_unavailable host stanza_id Nothing req 333 liftIO . atomically . writeTChan cmdChan . Send $ iq_service_unavailable host stanza_id Nothing req
334 case tagName child of 334 case tagName child of
335 -- "{http://jabber.org/protocol/disco#items}query" -> liftIO $ putStrLn "iq-get-query-items" 335 -- "{http://jabber.org/protocol/disco#items}query" -> liftIO $ debugStr "iq-get-query-items"
336 "{urn:xmpp:ping}ping" -> liftIO $ do 336 "{urn:xmpp:ping}ping" -> liftIO $ do
337 let mjid = lookupAttrib "from" (tagAttrs tag) 337 let mjid = lookupAttrib "from" (tagAttrs tag)
338 let pong = [ EventBeginElement "{jabber:client}iq" 338 let pong = [ EventBeginElement "{jabber:client}iq"
@@ -347,7 +347,7 @@ handleIQGet session cmdChan tag = do
347 ] 347 ]
348 atomically . writeTChan cmdChan . Send $ pong 348 atomically . writeTChan cmdChan . Send $ pong
349 "{jabber:iq:roster}query" -> liftIO $ do 349 "{jabber:iq:roster}query" -> liftIO $ do
350 putStrLn $ "REQUESTED ROSTER " ++ show tag 350 debugStr $ "REQUESTED ROSTER " ++ show tag
351 roster <- getRoster session stanza_id 351 roster <- getRoster session stanza_id
352 atomically $ do 352 atomically $ do
353 writeTChan cmdChan InterestedInRoster 353 writeTChan cmdChan InterestedInRoster
@@ -359,7 +359,7 @@ handleIQGet session cmdChan tag = do
359fromClient :: (MonadThrow m,MonadIO m, JabberClientSession session) => 359fromClient :: (MonadThrow m,MonadIO m, JabberClientSession session) =>
360 session -> TChan ClientCommands -> Sink XML.Event m () 360 session -> TChan ClientCommands -> Sink XML.Event m ()
361fromClient session cmdChan = doNestingXML $ do 361fromClient session cmdChan = doNestingXML $ do
362 let log = liftIO . L.putStrLn . ("(C) " <++>) 362 let log = liftIO . debugL . ("(C) " <++>)
363 send = liftIO . atomically . writeTChan cmdChan . Send 363 send = liftIO . atomically . writeTChan cmdChan . Send
364 withXML $ \begindoc -> do 364 withXML $ \begindoc -> do
365 when (begindoc==EventBeginDocument) $ do 365 when (begindoc==EventBeginDocument) $ do
@@ -378,7 +378,7 @@ fromClient session cmdChan = doNestingXML $ do
378 whenJust nextElement $ \stanza -> do 378 whenJust nextElement $ \stanza -> do
379 stanza_lvl <- nesting 379 stanza_lvl <- nesting
380 380
381 liftIO . putStrLn $ "stanza: "++show stanza 381 liftIO . debugStr $ "stanza: "++show stanza
382 382
383 let unhandledStanza = do 383 let unhandledStanza = do
384 xs <- gatherElement stanza Seq.empty 384 xs <- gatherElement stanza Seq.empty
@@ -443,9 +443,9 @@ toClient session pchan cmdChan rchan = toClient' False False
443 CmdChan (Send xs) -> send xs >> loop 443 CmdChan (Send xs) -> send xs >> loop
444 CmdChan BoundToResource -> toClient' True isInterested 444 CmdChan BoundToResource -> toClient' True isInterested
445 CmdChan InterestedInRoster -> do 445 CmdChan InterestedInRoster -> do
446 liftIO . putStrLn $ "Roster: interested" 446 liftIO . debugStr $ "Roster: interested"
447 toClient' isBound True 447 toClient' isBound True
448 -- CmdChan cmd -> liftIO (putStrLn $ "unhandled event: "++show cmd) >> loop 448 -- CmdChan cmd -> liftIO (debugStr $ "unhandled event: "++show cmd) >> loop
449 RChan (RequestedSubscription who contact) -> do 449 RChan (RequestedSubscription who contact) -> do
450 jid <- liftIO $ getJID session 450 jid <- liftIO $ getJID session
451 when (isInterested && Just who==name jid) $ do 451 when (isInterested && Just who==name jid) $ do
@@ -453,7 +453,7 @@ toClient session pchan cmdChan rchan = toClient' False False
453 send r 453 send r
454 loop 454 loop
455 RChan (NewBuddy who contact) -> do 455 RChan (NewBuddy who contact) -> do
456 liftIO . putStrLn $ "Roster push: NewBuddy "++show (isInterested,who,contact) 456 liftIO . debugStr $ "Roster push: NewBuddy "++show (isInterested,who,contact)
457 (jid,me) <- liftIO $ do 457 (jid,me) <- liftIO $ do
458 jid <- getJID session 458 jid <- getJID session
459 me <- asHostNameJID jid 459 me <- asHostNameJID jid
@@ -469,14 +469,14 @@ toClient session pchan cmdChan rchan = toClient' False False
469 let f True = "both" 469 let f True = "both"
470 f False = "to" 470 f False = "to"
471 subscription <- fmap f (liftIO $ isSubscribed session contact) 471 subscription <- fmap f (liftIO $ isSubscribed session contact)
472 r <- liftIO . handleIO (\e -> putStrLn ("Roster NewBuddy error: "++show e) >> return []) $ do 472 r <- liftIO . handleIO (\e -> debugStr ("Roster NewBuddy error: "++show e) >> return []) $ do
473 rosterPush jid 473 rosterPush jid
474 (toStrict . L.decodeUtf8 $ contact) 474 (toStrict . L.decodeUtf8 $ contact)
475 [attr "subscription" subscription] 475 [attr "subscription" subscription]
476 send r 476 send r
477 loop 477 loop
478 RChan (RemovedBuddy who contact) -> do 478 RChan (RemovedBuddy who contact) -> do
479 liftIO . putStrLn $ "Roster push: RemovedBuddy "++show (isInterested,who,contact) 479 liftIO . debugStr $ "Roster push: RemovedBuddy "++show (isInterested,who,contact)
480 (jid,me) <- liftIO $ do 480 (jid,me) <- liftIO $ do
481 jid <- getJID session 481 jid <- getJID session
482 me <- asHostNameJID jid 482 me <- asHostNameJID jid
@@ -492,14 +492,14 @@ toClient session pchan cmdChan rchan = toClient' False False
492 let f True = "from" 492 let f True = "from"
493 f False = "none" 493 f False = "none"
494 subscription <- fmap f (liftIO $ isSubscribed session contact) 494 subscription <- fmap f (liftIO $ isSubscribed session contact)
495 r <- liftIO . handleIO (\e -> putStrLn ("Roster RemovedBuddy error: "++show e) >> return []) $ do 495 r <- liftIO . handleIO (\e -> debugStr ("Roster RemovedBuddy error: "++show e) >> return []) $ do
496 rosterPush jid 496 rosterPush jid
497 (toStrict . L.decodeUtf8 $ contact) 497 (toStrict . L.decodeUtf8 $ contact)
498 [attr "subscription" subscription] 498 [attr "subscription" subscription]
499 send r 499 send r
500 loop 500 loop
501 RChan (NewSubscriber who contact) -> do 501 RChan (NewSubscriber who contact) -> do
502 liftIO . putStrLn $ "Roster push: NewSubscriber "++show (isInterested,who,contact) 502 liftIO . debugStr $ "Roster push: NewSubscriber "++show (isInterested,who,contact)
503 (jid,me) <- liftIO $ do 503 (jid,me) <- liftIO $ do
504 jid <- getJID session 504 jid <- getJID session
505 me <- asHostNameJID jid 505 me <- asHostNameJID jid
@@ -509,14 +509,14 @@ toClient session pchan cmdChan rchan = toClient' False False
509 let f True = "both" 509 let f True = "both"
510 f False = "from" 510 f False = "from"
511 subscription <- fmap f (liftIO $ isBuddy session contact) 511 subscription <- fmap f (liftIO $ isBuddy session contact)
512 r <- liftIO . handleIO (\e -> putStrLn ("Roster NewSubscriber error: "++show e) >> return []) $ do 512 r <- liftIO . handleIO (\e -> debugStr ("Roster NewSubscriber error: "++show e) >> return []) $ do
513 rosterPush jid 513 rosterPush jid
514 (toStrict . L.decodeUtf8 $ contact) 514 (toStrict . L.decodeUtf8 $ contact)
515 [attr "subscription" subscription] 515 [attr "subscription" subscription]
516 send r 516 send r
517 loop 517 loop
518 RChan (RejectSubscriber who contact) -> do 518 RChan (RejectSubscriber who contact) -> do
519 liftIO . putStrLn $ "Roster push: RejectSubscriber "++show (isInterested,who,contact) 519 liftIO . debugStr $ "Roster push: RejectSubscriber "++show (isInterested,who,contact)
520 (jid,me) <- liftIO $ do 520 (jid,me) <- liftIO $ do
521 jid <- getJID session 521 jid <- getJID session
522 me <- asHostNameJID jid 522 me <- asHostNameJID jid
@@ -526,14 +526,14 @@ toClient session pchan cmdChan rchan = toClient' False False
526 let f True = "to" 526 let f True = "to"
527 f False = "none" 527 f False = "none"
528 subscription <- fmap f (liftIO $ isBuddy session contact) 528 subscription <- fmap f (liftIO $ isBuddy session contact)
529 r <- liftIO . handleIO (\e -> putStrLn ("Roster RejectSubscriber error: "++show e) >> return []) $ do 529 r <- liftIO . handleIO (\e -> debugStr ("Roster RejectSubscriber error: "++show e) >> return []) $ do
530 rosterPush jid 530 rosterPush jid
531 (toStrict . L.decodeUtf8 $ contact) 531 (toStrict . L.decodeUtf8 $ contact)
532 [attr "subscription" subscription] 532 [attr "subscription" subscription]
533 send r 533 send r
534 loop 534 loop
535 RChan (PendingSubscriber who contact) -> do 535 RChan (PendingSubscriber who contact) -> do
536 liftIO . putStrLn $ "Roster: Pending buddy "++show (isInterested,who,contact) 536 liftIO . debugStr $ "Roster: Pending buddy "++show (isInterested,who,contact)
537 (jid,me) <- liftIO $ do 537 (jid,me) <- liftIO $ do
538 jid <- getJID session 538 jid <- getJID session
539 me <- asHostNameJID jid 539 me <- asHostNameJID jid
@@ -563,7 +563,7 @@ handleClient st src snk = do
563 session_factory = hHead st' 563 session_factory = hHead st'
564 pname <- getPeerName sock 564 pname <- getPeerName sock
565 session <- newSession session_factory sock 565 session <- newSession session_factory sock
566 Prelude.putStrLn $ "PEER NAME: "++Prelude.show pname 566 debugStr $ "PEER NAME: "++Prelude.show pname
567 pchan <- subscribe session Nothing 567 pchan <- subscribe session Nothing
568 rchan <- subscribeToRoster session 568 rchan <- subscribeToRoster session
569 let cmdChan = clientChannel session 569 let cmdChan = clientChannel session
@@ -599,12 +599,12 @@ handlePeer st src snk = do
599 let HCons sock (HCons _ st') = st 599 let HCons sock (HCons _ st') = st
600 session_factory = hHead st' 600 session_factory = hHead st'
601 name <- fmap bshow $ getPeerName sock 601 name <- fmap bshow $ getPeerName sock
602 L.putStrLn $ "(P) connected " <++> name 602 debugL $ "(P) connected " <++> name
603 session <- newPeerSession session_factory sock 603 session <- newPeerSession session_factory sock
604 604
605 finally ( src $= parseBytes def $$ fromPeer session ) 605 finally ( src $= parseBytes def $$ fromPeer session )
606 $ do 606 $ do
607 L.putStrLn $ "(P) disconnected " <++> name 607 debugL $ "(P) disconnected " <++> name
608 closePeerSession session 608 closePeerSession session
609 609
610 610
@@ -615,7 +615,7 @@ handlePeerPresence session stanza False = do
615 liftIO $ announcePresence session (Presence peer_jid Offline) 615 liftIO $ announcePresence session (Presence peer_jid Offline)
616handlePeerPresence session stanza True = do 616handlePeerPresence session stanza True = do
617 -- online (Available or Away) 617 -- online (Available or Away)
618 let log = liftIO . L.putStrLn . ("(P) " <++>) 618 let log = liftIO . debugL . ("(P) " <++>)
619 withJust (lookupAttrib "from" (tagAttrs stanza)) $ \jid -> do 619 withJust (lookupAttrib "from" (tagAttrs stanza)) $ \jid -> do
620 pjid <- liftIO $ parseAddressJID (textToByteString jid) 620 pjid <- liftIO $ parseAddressJID (textToByteString jid)
621 -- stat <- show element content 621 -- stat <- show element content
@@ -671,15 +671,15 @@ handlePresenceProbe session stanza = do
671 -- withJust (lookupAttrib "from" (tagAttrs stanza)) $ \from -> do 671 -- withJust (lookupAttrib "from" (tagAttrs stanza)) $ \from -> do
672 jid <- liftIO $ parseAddressJID $ textToByteString to 672 jid <- liftIO $ parseAddressJID $ textToByteString to
673 withJust (name jid) $ \user -> do 673 withJust (name jid) $ \user -> do
674 liftIO $ L.putStrLn $ "RECEIVED PROBE "<++>bshow (peerAddress session,to) 674 liftIO $ debugL $ "RECEIVED PROBE "<++>bshow (peerAddress session,to)
675 liftIO $ do 675 liftIO $ do
676 subs <- getSubscribers (peerSessionFactory session) user 676 subs <- getSubscribers (peerSessionFactory session) user
677 liftIO $ L.putStrLn $ "subscribers for "<++>bshow user<++>": " <++>bshow subs 677 liftIO $ debugL $ "subscribers for "<++>bshow user<++>": " <++>bshow subs
678 forM_ subs $ \jidstr -> do 678 forM_ subs $ \jidstr -> do
679 handleIO_ (return ()) $ do 679 handleIO_ (return ()) $ do
680 L.putStrLn $ "parsing " <++>jidstr 680 debugL $ "parsing " <++>jidstr
681 sub <- parseHostNameJID jidstr 681 sub <- parseHostNameJID jidstr
682 putStrLn $ "comparing " ++show (peer sub , peerAddress session) 682 debugStr $ "comparing " ++show (peer sub , peerAddress session)
683 when (peer sub == discardPort (peerAddress session)) $ do 683 when (peer sub == discardPort (peerAddress session)) $ do
684 ps <- userStatus session user 684 ps <- userStatus session user
685 -- todo: Consider making this a directed presence 685 -- todo: Consider making this a directed presence
@@ -719,24 +719,24 @@ presenceSubscribed from = return
719 719
720clientRequestsSubscription session cmdChan stanza = do 720clientRequestsSubscription session cmdChan stanza = do
721 liftIO $ do 721 liftIO $ do
722 putStrLn $ "CLIENT PRESENCE SUBSCRIBE " ++ show stanza 722 debugStr $ "CLIENT PRESENCE SUBSCRIBE " ++ show stanza
723 withJust (lookupAttrib "to" (tagAttrs stanza)) $ \to_str0 -> do 723 withJust (lookupAttrib "to" (tagAttrs stanza)) $ \to_str0 -> do
724 let to_str = S.takeWhile (/='/') to_str0 724 let to_str = S.takeWhile (/='/') to_str0
725 from = lookupAttrib "from" (tagAttrs stanza) 725 from = lookupAttrib "from" (tagAttrs stanza)
726 iqid = lookupAttrib "id" (tagAttrs stanza) 726 iqid = lookupAttrib "id" (tagAttrs stanza)
727 let handleError e | isDoesNotExistError e = do 727 let handleError e | isDoesNotExistError e = do
728 putStrLn $ "remote-server-not-found" 728 debugStr $ "remote-server-not-found"
729 r <- presenceErrorRemoteNotFound iqid from to_str 729 r <- presenceErrorRemoteNotFound iqid from to_str
730 atomically $ writeTChan cmdChan (Send r) 730 atomically $ writeTChan cmdChan (Send r)
731 handleError e = do 731 handleError e = do
732 putStrLn $ "ERROR: "++ show e 732 debugStr $ "ERROR: "++ show e
733 handleIO handleError $ do 733 handleIO handleError $ do
734 let to_str' = textToByteString to_str 734 let to_str' = textToByteString to_str
735 to_jid <- fmap bare $ parseHostNameJID to_str' 735 to_jid <- fmap bare $ parseHostNameJID to_str'
736 if (is_remote . peer) to_jid 736 if (is_remote . peer) to_jid
737 then do 737 then do
738 addSolicited session to_str' to_jid 738 addSolicited session to_str' to_jid
739 putStrLn $ "added to solicited: " ++ show to_jid 739 debugStr $ "added to solicited: " ++ show to_jid
740 else do 740 else do
741 -- addLocalSubscriber session to_str 741 -- addLocalSubscriber session to_str
742 -- self <- getJID session 742 -- self <- getJID session
@@ -763,9 +763,9 @@ stanzaFromTo session stanza =
763 return $ Just (fromjid,to) 763 return $ Just (fromjid,to)
764 764
765peerRequestsSubsription session stanza = do 765peerRequestsSubsription session stanza = do
766 liftIO $ putStrLn $ "PEER PRESENCE SUBSCRIBE " ++ show stanza 766 liftIO $ debugStr $ "PEER PRESENCE SUBSCRIBE " ++ show stanza
767 767
768 whenJust (liftIO . handleIO (\e -> putStrLn ("peerRequestsSubsription: "++show e) >> return Nothing) 768 whenJust (liftIO . handleIO (\e -> debugStr ("peerRequestsSubsription: "++show e) >> return Nothing)
769 $ stanzaFromTo session stanza) $ \(fromjid,tojid) -> do 769 $ stanzaFromTo session stanza) $ \(fromjid,tojid) -> do
770 withJust (name tojid) $ \user -> do 770 withJust (name tojid) $ \user -> do
771 771
@@ -777,7 +777,7 @@ peerRequestsSubsription session stanza = do
777 return (catMaybes msubs) 777 return (catMaybes msubs)
778 if elem fromjid subs 778 if elem fromjid subs
779 then do 779 then do
780 liftIO . L.putStrLn $ bshow fromjid <++> " already subscribed to " <++> user 780 liftIO . debugL $ bshow fromjid <++> " already subscribed to " <++> user
781 -- if already subscribed, reply 781 -- if already subscribed, reply
782 liftIO $ do 782 liftIO $ do
783 sendPeerMessage session (Approval tojid fromjid) 783 sendPeerMessage session (Approval tojid fromjid)
@@ -788,25 +788,25 @@ peerRequestsSubsription session stanza = do
788 liftIO $ processRequest session user fromjid 788 liftIO $ processRequest session user fromjid
789 789
790clientApprovesSubscription session stanza = do 790clientApprovesSubscription session stanza = do
791 liftIO $ putStrLn $ "CLIENT APPROVES SUBSCRIPTION" 791 liftIO $ debugStr $ "CLIENT APPROVES SUBSCRIPTION"
792 withJust (lookupAttrib "to" (tagAttrs stanza)) $ \to_str -> do 792 withJust (lookupAttrib "to" (tagAttrs stanza)) $ \to_str -> do
793 liftIO $ approveSubscriber session (textToByteString to_str) 793 liftIO $ approveSubscriber session (textToByteString to_str)
794 794
795clientRejectsSubscription session stanza = do 795clientRejectsSubscription session stanza = do
796 liftIO $ putStrLn $ "CLIENT REJECTS SUBSCRIPTION" 796 liftIO $ debugStr $ "CLIENT REJECTS SUBSCRIPTION"
797 withJust (lookupAttrib "to" (tagAttrs stanza)) $ \to_str -> do 797 withJust (lookupAttrib "to" (tagAttrs stanza)) $ \to_str -> do
798 liftIO $ rejectSubscriber session (textToByteString to_str) 798 liftIO $ rejectSubscriber session (textToByteString to_str)
799 799
800peerApprovesSubscription session stanza = do 800peerApprovesSubscription session stanza = do
801 liftIO $ putStrLn $ "PEER APPROVES SUBSCRIPTION" 801 liftIO $ debugStr $ "PEER APPROVES SUBSCRIPTION"
802 whenJust (liftIO . handleIO (\e -> putStrLn ("peerApprovesSubscription: "++show e) >> return Nothing) 802 whenJust (liftIO . handleIO (\e -> debugStr ("peerApprovesSubscription: "++show e) >> return Nothing)
803 $ stanzaFromTo session stanza) $ \(fromjid,tojid) -> do 803 $ stanzaFromTo session stanza) $ \(fromjid,tojid) -> do
804 withJust (name tojid) $ \user -> do 804 withJust (name tojid) $ \user -> do
805 liftIO $ processApproval session user fromjid 805 liftIO $ processApproval session user fromjid
806 806
807peerRejectsSubscription session stanza = do 807peerRejectsSubscription session stanza = do
808 liftIO $ putStrLn $ "PEER REJECTS SUBSCRIPTION" 808 liftIO $ debugStr $ "PEER REJECTS SUBSCRIPTION"
809 whenJust (liftIO . handleIO (\e -> putStrLn ("peerRejectsSubscription: "++show e) >> return Nothing) 809 whenJust (liftIO . handleIO (\e -> debugStr ("peerRejectsSubscription: "++show e) >> return Nothing)
810 $ stanzaFromTo session stanza) $ \(fromjid,tojid) -> do 810 $ stanzaFromTo session stanza) $ \(fromjid,tojid) -> do
811 withJust (name tojid) $ \user -> do 811 withJust (name tojid) $ \user -> do
812 liftIO $ processRejection session user fromjid 812 liftIO $ processRejection session user fromjid
@@ -814,7 +814,7 @@ peerRejectsSubscription session stanza = do
814fromPeer :: (MonadThrow m,MonadIO m, JabberPeerSession session) => 814fromPeer :: (MonadThrow m,MonadIO m, JabberPeerSession session) =>
815 session -> Sink XML.Event m () 815 session -> Sink XML.Event m ()
816fromPeer session = doNestingXML $ do 816fromPeer session = doNestingXML $ do
817 let log = liftIO . L.putStrLn . ("(P) " <++>) 817 let log = liftIO . debugL . ("(P) " <++>)
818 withXML $ \begindoc -> do 818 withXML $ \begindoc -> do
819 when (begindoc==EventBeginDocument) $ do 819 when (begindoc==EventBeginDocument) $ do
820 log "begin-doc" 820 log "begin-doc"
@@ -927,7 +927,7 @@ toPeer
927 -> (Maybe OutBoundMessage -> IO ()) 927 -> (Maybe OutBoundMessage -> IO ())
928 -> ConduitM i [Event] IO () 928 -> ConduitM i [Event] IO ()
929toPeer sock cache chan fail = do 929toPeer sock cache chan fail = do
930 let -- log = liftIO . L.putStrLn . ("(>P) " <++>) 930 let -- log = liftIO . debugL . ("(>P) " <++>)
931 send xs = yield xs >> prettyPrint ">P: " xs -- >> return (3::Int) 931 send xs = yield xs >> prettyPrint ">P: " xs -- >> return (3::Int)
932 checkConnection cmd = do 932 checkConnection cmd = do
933 liftIO $ catchIO (getPeerName sock >> return ()) 933 liftIO $ catchIO (getPeerName sock >> return ())
@@ -935,7 +935,7 @@ toPeer sock cache chan fail = do
935 sendOrFail getXML cmd = do 935 sendOrFail getXML cmd = do
936 checkConnection cmd 936 checkConnection cmd
937 r <- liftIO $ getXML 937 r <- liftIO $ getXML
938 -- handleIO (\e -> putStrLn ("ERROR: "++show e) >> return []) getXML 938 -- handleIO (\e -> debugStr ("ERROR: "++show e) >> return []) getXML
939 yieldOr r (fail . Just $ cmd) 939 yieldOr r (fail . Just $ cmd)
940 prettyPrint ">P: " r 940 prettyPrint ">P: " r
941 sendPresence presence = 941 sendPresence presence =
@@ -957,7 +957,7 @@ toPeer sock cache chan fail = do
957 send greetPeer 957 send greetPeer
958 forM_ (Map.assocs . approvals $ cache) $ \(to,froms) -> do 958 forM_ (Map.assocs . approvals $ cache) $ \(to,froms) -> do
959 forM_ (Set.toList froms) $ \(approve,from) -> do 959 forM_ (Set.toList froms) $ \(approve,from) -> do
960 liftIO $ L.putStrLn "sending cached approval..." 960 liftIO $ debugL "sending cached approval..."
961 sendApproval approve from to 961 sendApproval approve from to
962 forM_ (Map.assocs . presences $ cache) $ \(jid,st) -> do 962 forM_ (Map.assocs . presences $ cache) $ \(jid,st) -> do
963 sendPresence (Presence jid st) 963 sendPresence (Presence jid st)
@@ -965,10 +965,10 @@ toPeer sock cache chan fail = do
965 forM_ (Set.toList froms) $ \(got,from) -> do 965 forM_ (Set.toList froms) $ \(got,from) -> do
966 if got 966 if got
967 then do 967 then do
968 liftIO $ L.putStrLn "sending cached probe..." 968 liftIO $ debugL "sending cached probe..."
969 sendProbe from to 969 sendProbe from to
970 else do 970 else do
971 liftIO $ L.putStrLn "sending cached solicitation..." 971 liftIO $ debugL "sending cached solicitation..."
972 sendSolicitation from to 972 sendSolicitation from to
973 973
974 974
@@ -977,16 +977,16 @@ toPeer sock cache chan fail = do
977 case event of 977 case event of
978 OutBoundPresence p -> sendPresence p 978 OutBoundPresence p -> sendPresence p
979 PresenceProbe from to -> do 979 PresenceProbe from to -> do
980 liftIO $ L.putStrLn "sending live probe..." 980 liftIO $ debugL "sending live probe..."
981 sendProbe from to 981 sendProbe from to
982 Solicitation from to -> do 982 Solicitation from to -> do
983 liftIO $ L.putStrLn "sending live solicitation..." 983 liftIO $ debugL "sending live solicitation..."
984 sendSolicitation from to 984 sendSolicitation from to
985 Approval from to -> do 985 Approval from to -> do
986 liftIO . L.putStrLn $ "sending approval "<++>bshow (from,to) 986 liftIO . debugL $ "sending approval "<++>bshow (from,to)
987 sendApproval True from to 987 sendApproval True from to
988 Rejection from to -> do 988 Rejection from to -> do
989 liftIO . L.putStrLn $ "sending rejection "<++>bshow (from,to) 989 liftIO . debugL $ "sending rejection "<++>bshow (from,to)
990 sendApproval False from to 990 sendApproval False from to
991 loop 991 loop
992 send goodbyePeer 992 send goodbyePeer
@@ -1001,13 +1001,13 @@ seekRemotePeers config chan server_connections = do
1001 event <- atomically $ readTChan chan 1001 event <- atomically $ readTChan chan
1002 case event of 1002 case event of
1003 p@(Presence jid stat) | not (is_remote (peer jid)) -> do 1003 p@(Presence jid stat) | not (is_remote (peer jid)) -> do
1004 -- L.putStrLn $ "seekRemotePeers: " <++> L.show jid <++> " " <++> bshow stat 1004 -- debugL $ "seekRemotePeers: " <++> L.show jid <++> " " <++> bshow stat
1005 runMaybeT $ do 1005 runMaybeT $ do
1006 u <- MaybeT . return $ name jid 1006 u <- MaybeT . return $ name jid
1007 subscribers <- liftIO $ do 1007 subscribers <- liftIO $ do
1008 subs <- getSubscribers config u 1008 subs <- getSubscribers config u
1009 mapM parseHostNameJID subs 1009 mapM parseHostNameJID subs
1010 -- liftIO . L.putStrLn $ "subscribers: " <++> bshow subscribers 1010 -- liftIO . debugL $ "subscribers: " <++> bshow subscribers
1011 let peers = Set.map peer (Set.fromList subscribers) 1011 let peers = Set.map peer (Set.fromList subscribers)
1012 forM_ (Set.toList peers) $ \peer -> do 1012 forM_ (Set.toList peers) $ \peer -> do
1013 when (is_remote peer) $ 1013 when (is_remote peer) $
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
31import Control.Exception hiding (catch) 31import Control.Exception hiding (catch)
32import LocalPeerCred 32import LocalPeerCred
33import System.Posix.User 33import System.Posix.User
34import Logging
34import qualified Data.Set as Set 35import qualified Data.Set as Set
35import Data.Set as Set (Set,(\\)) 36import Data.Set as Set (Set,(\\))
36import qualified Data.Map as Map 37import qualified Data.Map as Map
@@ -43,7 +44,7 @@ import Control.Monad.IO.Class
43 44
44import ByteStringOperators 45import ByteStringOperators
45import qualified Data.ByteString.Lazy.Char8 as L 46import qualified Data.ByteString.Lazy.Char8 as L
46import Data.ByteString.Lazy.Char8 as L (ByteString,putStrLn) 47import Data.ByteString.Lazy.Char8 as L (ByteString)
47import qualified Prelude 48import qualified Prelude
48import Prelude hiding (putStrLn) 49import Prelude hiding (putStrLn)
49import System.Environment 50import 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
494cmpJID newitem jid = do 495cmpJID 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
506addJid modify user jid = do 507addJid 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
603sendProbes state jid = do 604sendProbes 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
652on_chvt state vtnum = do 653on_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
711sendUSR1 pid = do 712sendUSR1 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