From c17c62985ba329a59e7711635bc0c0de0e5b621f Mon Sep 17 00:00:00 2001
From: Philipp Balzarek
Date: Thu, 19 Apr 2012 19:39:27 +0200
Subject: [PATCH] lifted xmppConnect (connect), xmppStartTLS(startTLS) and
xmppSASL(auth)
---
.gitignore | 1 +
src/Network/XMPP.hs | 16 +++++++++++++++-
src/Network/XMPP/Concurrent.hs | 14 ++++----------
src/Network/XMPP/Concurrent/Monad.hs | 2 ++
src/Tests.hs | 9 ++++-----
5 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/.gitignore b/.gitignore
index d7ddec5..f684ca1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
dist/
cabal-dev/
+wiki/
*.o
*.hi
*~
diff --git a/src/Network/XMPP.hs b/src/Network/XMPP.hs
index 8c531e3..76d87a8 100644
--- a/src/Network/XMPP.hs
+++ b/src/Network/XMPP.hs
@@ -42,11 +42,15 @@ module Network.XMPP
, module Network.XMPP.Message
, xmppConnect
, xmppNewSession
+ , connect
+ , startTLS
+ , auth
) where
import Data.Text as Text
import Network
+import qualified Network.TLS as TLS
import Network.XMPP.Bind
import Network.XMPP.Concurrent
import Network.XMPP.Message
@@ -62,4 +66,14 @@ xmppConnect :: HostName -> Text -> XMPPConMonad (Either StreamError ())
xmppConnect address hostname = xmppRawConnect address hostname >> xmppStartStream
xmppNewSession :: XMPPThread a -> IO (a, XMPPConState)
-xmppNewSession = withNewSession . runThreaded
\ No newline at end of file
+xmppNewSession = withNewSession . runThreaded
+
+
+startTLS :: TLS.TLSParams -> XMPPThread (Either XMPPTLSError ())
+startTLS = withConnection . xmppStartTLS
+
+auth :: Text.Text -> Text.Text -> XMPPThread (Either String Text.Text)
+auth username passwd = withConnection $ xmppSASL username passwd
+
+connect :: HostName -> Text -> XMPPThread (Either StreamError ())
+connect address hostname = withConnection $ xmppConnect address hostname
diff --git a/src/Network/XMPP/Concurrent.hs b/src/Network/XMPP/Concurrent.hs
index 19f4ef7..c360236 100644
--- a/src/Network/XMPP/Concurrent.hs
+++ b/src/Network/XMPP/Concurrent.hs
@@ -5,14 +5,8 @@ module Network.XMPP.Concurrent
, module Network.XMPP.Concurrent.IQ
) where
-import Network.XMPP.Concurrent.Types
-import Network.XMPP.Concurrent.Monad
-import Network.XMPP.Concurrent.Threads
-import Network.XMPP.Concurrent.IQ
-
-
-
-
-
-
+import Network.XMPP.Concurrent.Types
+import Network.XMPP.Concurrent.Monad
+import Network.XMPP.Concurrent.Threads
+import Network.XMPP.Concurrent.IQ
diff --git a/src/Network/XMPP/Concurrent/Monad.hs b/src/Network/XMPP/Concurrent/Monad.hs
index 017db4e..f9a2d75 100644
--- a/src/Network/XMPP/Concurrent/Monad.hs
+++ b/src/Network/XMPP/Concurrent/Monad.hs
@@ -16,6 +16,7 @@ import Data.Text(Text)
import Network.XMPP.Concurrent.Types
import Network.XMPP.Monad
+
-- | Register a new IQ listener. IQ requests matching the type and namespace will
-- be put in the channel.
listenIQChan :: IQRequestType -- ^ type of IQs to receive (Get / Set)
@@ -196,3 +197,4 @@ endSession = do -- TODO: This has to be idempotent (is it?)
-- | Close the connection to the server
closeConnection :: XMPPThread ()
closeConnection = withConnection xmppKillConnection
+
diff --git a/src/Tests.hs b/src/Tests.hs
index 07b5602..3b46959 100644
--- a/src/Tests.hs
+++ b/src/Tests.hs
@@ -86,11 +86,10 @@ runMain debug number = do
debug . (("Thread " ++ show number ++ ":") ++)
xmppNewSession $ do
debug' "running"
- withConnection $ do
- xmppConnect "localhost" "species64739.dyndns.org"
- xmppStartTLS exampleParams
- saslResponse <- xmppSASL (fromJust $ localpart we) "pwd"
- case saslResponse of
+ connect "localhost" "species64739.dyndns.org"
+ startTLS exampleParams
+ saslResponse <- auth (fromJust $ localpart we) "pwd"
+ case saslResponse of
Right _ -> return ()
Left e -> error e
xmppThreadedBind (resourcepart we)