diff options
-rw-r--r-- | Presence/XMPPServer.hs | 22 | ||||
-rw-r--r-- | xmppServer.hs | 9 |
2 files changed, 20 insertions, 11 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs index 41d60a07..e78e4dd9 100644 --- a/Presence/XMPPServer.hs +++ b/Presence/XMPPServer.hs | |||
@@ -192,6 +192,7 @@ data XMPPServerParameters = | |||
192 | , xmppPeerSubscriptionRequest :: IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO () | 192 | , xmppPeerSubscriptionRequest :: IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO () |
193 | , xmppClientInformSubscription :: IO () -> ConnectionKey -> Stanza -> IO () | 193 | , xmppClientInformSubscription :: IO () -> ConnectionKey -> Stanza -> IO () |
194 | , xmppPeerInformSubscription :: IO () -> ConnectionKey -> Stanza -> IO () | 194 | , xmppPeerInformSubscription :: IO () -> ConnectionKey -> Stanza -> IO () |
195 | , xmppVerbosity :: IO Int | ||
195 | } | 196 | } |
196 | 197 | ||
197 | 198 | ||
@@ -1253,15 +1254,15 @@ forkConnection sv xmpp k laddr pingflag src snk stanzas = do | |||
1253 | msgids <- atomically $ newTVar [] | 1254 | msgids <- atomically $ newTVar [] |
1254 | forkIO $ do | 1255 | forkIO $ do |
1255 | -- mapM_ (atomically . Slotted.push slots Nothing) greetPeer | 1256 | -- mapM_ (atomically . Slotted.push slots Nothing) greetPeer |
1257 | verbosity <- xmppVerbosity xmpp | ||
1256 | fix $ \loop -> do | 1258 | fix $ \loop -> do |
1257 | what <- atomically $ foldr1 orElse | 1259 | what <- atomically $ foldr1 orElse |
1258 | [readTChan output >>= \stanza -> return $ do | 1260 | [readTChan output >>= \stanza -> return $ do |
1259 | #ifndef PINGNOISE | 1261 | let notping f |
1260 | let notping f = case stanzaType stanza of Pong -> return () | 1262 | | (verbosity==1) = case stanzaType stanza of Pong -> return () |
1261 | _ -> f | 1263 | _ -> f |
1262 | #else | 1264 | | (verbosity>=2) = f |
1263 | let notping f = f | 1265 | | otherwise = return () |
1264 | #endif | ||
1265 | -- isempty <- atomically $ isEmptyTChan (stanzaChan stanza) | 1266 | -- isempty <- atomically $ isEmptyTChan (stanzaChan stanza) |
1266 | -- kwlog $ "queuing: "++show (isempty, stanzaId stanza) | 1267 | -- kwlog $ "queuing: "++show (isempty, stanzaId stanza) |
1267 | notping $ do | 1268 | notping $ do |
@@ -1739,11 +1740,12 @@ monitor sv params xmpp = do | |||
1739 | deliver replyto | 1740 | deliver replyto |
1740 | _ -> return () | 1741 | _ -> return () |
1741 | -- We need to clone in the case the stanza is passed on as for Message. | 1742 | -- We need to clone in the case the stanza is passed on as for Message. |
1742 | #ifndef PINGNOISE | 1743 | verbosity <- xmppVerbosity xmpp |
1743 | let notping f = case stanzaType stanza of Pong -> return () | 1744 | let notping f | (verbosity==1) = case stanzaType stanza of Pong -> return () |
1744 | _ -> f | 1745 | _ -> f |
1746 | | (verbosity>=2) = f | ||
1747 | | otherwise = return () | ||
1745 | notping $ do | 1748 | notping $ do |
1746 | #endif | ||
1747 | let typ = Strict8.pack $ c ++ "->"++(concat . take 1 . words $ show (stanzaType stanza))++" " | 1749 | let typ = Strict8.pack $ c ++ "->"++(concat . take 1 . words $ show (stanzaType stanza))++" " |
1748 | c = case stanzaOrigin stanza of | 1750 | c = case stanzaOrigin stanza of |
1749 | LocalPeer -> "*" | 1751 | LocalPeer -> "*" |
diff --git a/xmppServer.hs b/xmppServer.hs index a406366a..118a16b2 100644 --- a/xmppServer.hs +++ b/xmppServer.hs | |||
@@ -1,5 +1,7 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings #-} |
2 | {-# LANGUAGE TupleSections #-} | 2 | {-# LANGUAGE TupleSections #-} |
3 | {-# LANGUAGE LambdaCase #-} | ||
4 | import System.Environment | ||
3 | import System.Posix.Signals | 5 | import System.Posix.Signals |
4 | import Control.Concurrent (threadDelay,forkIO,forkOS,killThread,throwTo) | 6 | import Control.Concurrent (threadDelay,forkIO,forkOS,killThread,throwTo) |
5 | import Control.Concurrent.STM | 7 | import Control.Concurrent.STM |
@@ -11,7 +13,7 @@ import Network.Socket ( SockAddr(..) ) | |||
11 | import System.Endian (fromBE32) | 13 | import System.Endian (fromBE32) |
12 | import Data.List (nub, (\\), intersect, groupBy, sort, sortBy ) | 14 | import Data.List (nub, (\\), intersect, groupBy, sort, sortBy ) |
13 | import Data.Ord (comparing ) | 15 | import Data.Ord (comparing ) |
14 | import Data.Monoid ( (<>) ) | 16 | import Data.Monoid ( (<>), Sum(..), getSum ) |
15 | import qualified Data.Text as Text | 17 | import qualified Data.Text as Text |
16 | import qualified Data.Text.IO as Text | 18 | import qualified Data.Text.IO as Text |
17 | import qualified Data.Text.Encoding as Text | 19 | import qualified Data.Text.Encoding as Text |
@@ -956,6 +958,10 @@ peerInformSubscription state fail k stanza = do | |||
956 | chan | 958 | chan |
957 | 959 | ||
958 | main = runResourceT $ do | 960 | main = runResourceT $ do |
961 | args <- liftIO getArgs | ||
962 | let verbosity = getSum $ flip foldMap args $ \case | ||
963 | ('-':xs) -> Sum $ length (filter (=='-') xs) | ||
964 | _ -> mempty | ||
959 | cw <- liftIO newConsoleWriter | 965 | cw <- liftIO newConsoleWriter |
960 | state <- liftIO . atomically $ do | 966 | state <- liftIO . atomically $ do |
961 | clients <- newTVar Map.empty | 967 | clients <- newTVar Map.empty |
@@ -996,6 +1002,7 @@ main = runResourceT $ do | |||
996 | , xmppPeerSubscriptionRequest = peerSubscriptionRequest state | 1002 | , xmppPeerSubscriptionRequest = peerSubscriptionRequest state |
997 | , xmppClientInformSubscription = clientInformSubscription state | 1003 | , xmppClientInformSubscription = clientInformSubscription state |
998 | , xmppPeerInformSubscription = peerInformSubscription state | 1004 | , xmppPeerInformSubscription = peerInformSubscription state |
1005 | , xmppVerbosity = return verbosity | ||
999 | } | 1006 | } |
1000 | liftIO $ do | 1007 | liftIO $ do |
1001 | atomically $ putTMVar (server state) sv | 1008 | atomically $ putTMVar (server state) sv |