1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
{-# 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 ()
|