{-# LANGUAGE OverloadedStrings #-} import System.Posix.Signals import Control.Concurrent.STM import Control.Monad.Trans.Resource (runResourceT) import Control.Monad.IO.Class (MonadIO, liftIO) import Network.Socket ( addrAddress , getAddrInfo , defaultHints , addrFlags , AddrInfoFlag(AI_CANONNAME) ) import Data.Monoid ( (<>) ) import qualified Data.Text.IO as Text import Control.Monad import XMPPServer import Server main = runResourceT $ do (sv,peer_params) <- xmppServer XMPPServerParameters { xmppChooseResourceName = \k sock desired -> return "nobody@localhost/tty666" , xmppTellMyNameToClient = return "localhost" , xmppTellMyNameToPeer = \addr -> return "localhost" , xmppNewConnection = \k outchan -> return () , xmppEOF = \k -> return () , xmppRosterBuddies = \k -> return [] , xmppRosterSubscribers = \k -> return [] , xmppRosterSolicited = \k -> return [] , xmppRosterOthers = \k -> return [] , xmppSubscribeToRoster = \k -> return () , xmppLookupPeerName = \k -> return "localhost" , xmppLookupClientJID = \k -> return "nobody@localhost/tty666" , xmppDeliverMessage = \fail msg -> do let msgs = msgLangMap (stanzaType msg) body = fmap (maybe "" id . msgBody . snd) $ take 1 msgs when (not $ null body) $ do Text.putStrLn $ "MESSAGE " <> head body return () , xmppInformClientPresence = \k stanza -> return () } liftIO $ do let testaddr0 = "fd97:ca88:fa7c:b94b:c8b8:fad4:1021:a54d" -- testaddr0 = "fdef:9e0b:b502:52c3:c074:28d3:fcd7:bfb7" testaddr<- fmap (addrAddress . head) $ getAddrInfo (Just $ defaultHints { addrFlags = [ AI_CANONNAME ]}) (Just testaddr0) (Just "5269") putStrLn $ "Connecting to "++show testaddr control sv (ConnectWithEndlessRetry testaddr peer_params 10000) quitVar <- newEmptyTMVarIO installHandler sigTERM (CatchOnce (atomically $ putTMVar quitVar True)) Nothing installHandler sigINT (CatchOnce (atomically $ putTMVar quitVar True)) Nothing quitMessage <- atomically $ takeTMVar quitVar putStrLn "goodbye." return ()