summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-25 07:33:47 -0400
committerjoe <joe@jerkface.net>2018-06-25 16:42:20 -0400
commitd1e0191f6ea329ba2ffbc1b99fd41b5aec68765b (patch)
tree378796f0e1ed4a3914f11aec45d5e05e2bf6c011 /examples
parentfab0ea6ff17b2109b20ebffcef9262b1684203ca (diff)
Forward instant messages from XMPP clients to Tox peers.
Diffstat (limited to 'examples')
-rw-r--r--examples/dhtd.hs14
-rw-r--r--examples/test-xmpp.hs41
2 files changed, 52 insertions, 3 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index fefec650..e099334e 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -1982,14 +1982,22 @@ main = do
1982 xmppSink = newXmmpSink netcrypto 1982 xmppSink = newXmmpSink netcrypto
1983 forM_ msv $ \sv -> do 1983 forM_ msv $ \sv -> do
1984 let Tox.HaveDHTKey saddr = Tox.ncSockAddr netcrypto 1984 let Tox.HaveDHTKey saddr = Tox.ncSockAddr netcrypto
1985 announceToxJabberPeer (Tox.ncMyPublicKey netcrypto) (Tox.ncTheirPublicKey netcrypto) (xmppEventChannel sv) addrTox saddr pingflag xmppSrc xmppSink 1985 Tox.HaveDHTKey dkey = Tox.ncTheirDHTKey netcrypto
1986 nid = Tox.key2id dkey
1987 them = Tox.ncTheirPublicKey netcrypto
1988 me = Tox.ncMyPublicKey netcrypto
1989 announceToxJabberPeer me them (xmppEventChannel sv) addrTox saddr pingflag xmppSrc xmppSink
1986 forM_ mbtox $ \tox -> do 1990 forM_ mbtox $ \tox -> do
1987 let ContactInfo{accounts} = Tox.toxContactInfo tox 1991 let ContactInfo{accounts} = Tox.toxContactInfo tox
1988 mbacc <- HashMap.lookup (Tox.key2id $ Tox.ncMyPublicKey netcrypto) 1992 mbacc <- HashMap.lookup (Tox.key2id me)
1989 <$> atomically (readTVar accounts) 1993 <$> atomically (readTVar accounts)
1994 -- TODO: Add account if it doesn't exist?
1990 forM_ mbacc $ \acnt -> do 1995 forM_ mbacc $ \acnt -> do
1991 now <- getPOSIXTime 1996 now <- getPOSIXTime
1992 atomically $ setEstablished now (Tox.ncTheirPublicKey netcrypto) acnt 1997 forM_ (either (const Nothing) Just $ Tox.nodeInfo nid saddr)
1998 $ \ni -> do
1999 atomically $ do setEstablished now them acnt
2000 setContactAddr now them ni acnt
1993 atomically $ do 2001 atomically $ do
1994 supply <- readTVar (Tox.listenerIDSupply netCryptoSessionsState) 2002 supply <- readTVar (Tox.listenerIDSupply netCryptoSessionsState)
1995 let (listenerId,supply') = freshId supply 2003 let (listenerId,supply') = freshId supply
diff --git a/examples/test-xmpp.hs b/examples/test-xmpp.hs
new file mode 100644
index 00000000..a8e20c3c
--- /dev/null
+++ b/examples/test-xmpp.hs
@@ -0,0 +1,41 @@
1
2import Control.Monad.IO.Class
3import Control.Monad.Trans.Resource
4-- import Control.Monad.Trans.Class
5import Data.Conduit
6import Data.Conduit.List as CL
7-- import Data.XML.Types
8import System.Environment
9import Text.XML.Stream.Parse
10
11import XMPPToTox
12
13{-
14parse :: ConduitM Event o (ResourceT IO) ()
15parse = do
16 return ()
17-}
18
19showTox :: CryptoMessage -> ResourceT IO ()
20showTox = liftIO . print
21
22main :: IO ()
23main = do
24 args <- getArgs
25 let xmlfile = args !! 0
26
27 -- runConduit :: Monad m => ConduitM () Void m r -> m r
28
29 -- test-xmpp.hs:19:51: warning: [-Wdeprecations]
30 -- In the use of ‘$$’
31 -- (imported from Data.Conduit, but defined in conduit-1.3.0.3:Data.Conduit.Internal.Conduit):
32 -- Deprecated: "Use runConduit and .|"
33 --
34 -- runResourceT $ parseFile def xmlfile =$= parse $$ return ()
35
36 runResourceT $ runConduit $ do
37 parseFile def xmlfile
38 .| xmppToTox
39 -- CL.mapM_ :: Monad m => (a -> m ()) -> ConduitT a o m ()
40 .| CL.mapM_ showTox
41