Browse Source

lifted xmppConnect (connect), xmppStartTLS(startTLS) and xmppSASL(auth)

master
Philipp Balzarek 14 years ago
parent
commit
c17c62985b
  1. 1
      .gitignore
  2. 14
      src/Network/XMPP.hs
  3. 6
      src/Network/XMPP/Concurrent.hs
  4. 2
      src/Network/XMPP/Concurrent/Monad.hs
  5. 7
      src/Tests.hs

1
.gitignore vendored

@ -1,5 +1,6 @@
dist/ dist/
cabal-dev/ cabal-dev/
wiki/
*.o *.o
*.hi *.hi
*~ *~

14
src/Network/XMPP.hs

@ -42,11 +42,15 @@ module Network.XMPP
, module Network.XMPP.Message , module Network.XMPP.Message
, xmppConnect , xmppConnect
, xmppNewSession , xmppNewSession
, connect
, startTLS
, auth
) where ) where
import Data.Text as Text import Data.Text as Text
import Network import Network
import qualified Network.TLS as TLS
import Network.XMPP.Bind import Network.XMPP.Bind
import Network.XMPP.Concurrent import Network.XMPP.Concurrent
import Network.XMPP.Message import Network.XMPP.Message
@ -63,3 +67,13 @@ xmppConnect address hostname = xmppRawConnect address hostname >> xmppStartStre
xmppNewSession :: XMPPThread a -> IO (a, XMPPConState) xmppNewSession :: XMPPThread a -> IO (a, XMPPConState)
xmppNewSession = withNewSession . runThreaded 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

6
src/Network/XMPP/Concurrent.hs

@ -10,9 +10,3 @@ import Network.XMPP.Concurrent.Monad
import Network.XMPP.Concurrent.Threads import Network.XMPP.Concurrent.Threads
import Network.XMPP.Concurrent.IQ import Network.XMPP.Concurrent.IQ

2
src/Network/XMPP/Concurrent/Monad.hs

@ -16,6 +16,7 @@ import Data.Text(Text)
import Network.XMPP.Concurrent.Types import Network.XMPP.Concurrent.Types
import Network.XMPP.Monad import Network.XMPP.Monad
-- | Register a new IQ listener. IQ requests matching the type and namespace will -- | Register a new IQ listener. IQ requests matching the type and namespace will
-- be put in the channel. -- be put in the channel.
listenIQChan :: IQRequestType -- ^ type of IQs to receive (Get / Set) 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 -- | Close the connection to the server
closeConnection :: XMPPThread () closeConnection :: XMPPThread ()
closeConnection = withConnection xmppKillConnection closeConnection = withConnection xmppKillConnection

7
src/Tests.hs

@ -86,10 +86,9 @@ runMain debug number = do
debug . (("Thread " ++ show number ++ ":") ++) debug . (("Thread " ++ show number ++ ":") ++)
xmppNewSession $ do xmppNewSession $ do
debug' "running" debug' "running"
withConnection $ do connect "localhost" "species64739.dyndns.org"
xmppConnect "localhost" "species64739.dyndns.org" startTLS exampleParams
xmppStartTLS exampleParams saslResponse <- auth (fromJust $ localpart we) "pwd"
saslResponse <- xmppSASL (fromJust $ localpart we) "pwd"
case saslResponse of case saslResponse of
Right _ -> return () Right _ -> return ()
Left e -> error e Left e -> error e

Loading…
Cancel
Save