Browse Source

Work with lts-17.14

master
Denis Tereshkin 5 years ago
parent
commit
2a4d37b616
  1. 47
      Setup.hs
  2. 2
      pontarius-xmpp.cabal
  3. 32
      source/Network/Xmpp/Concurrent.hs
  4. 46
      source/Network/Xmpp/Concurrent/Types.hs
  5. 20
      source/Network/Xmpp/IM/PresenceTracker.hs
  6. 120
      source/Network/Xmpp/Stream.hs
  7. 20
      source/Network/Xmpp/Types.hs
  8. 12
      stack.yaml

47
Setup.hs

@ -1,45 +1,2 @@
-- pilfered from lens package import Distribution.Simple
{-# OPTIONS_GHC -Wall #-} main = defaultMain
module Main (main) where
import Distribution.Package ( PackageName, Package, PackageId, InstalledPackageId, packageVersion, packageName, unPackageName )
import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )
import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose, copyFiles, ordNub )
import Distribution.Simple.BuildPaths ( autogenModulesDir )
import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), Flag(..), fromFlag, HaddockFlags(haddockDistPref))
import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
import Distribution.Text ( display )
import Distribution.Types.MungedPackageId ( MungedPackageId(mungedName, mungedVersion) )
import Distribution.Types.MungedPackageName ( MungedPackageName, unMungedPackageName )
import Distribution.Types.UnqualComponentName ( unUnqualComponentName )
import Distribution.Verbosity ( Verbosity, normal )
import Distribution.Version ( showVersion )
import System.FilePath ( (</>) )
main :: IO ()
main = defaultMainWithHooks simpleUserHooks
{ buildHook = \pkg lbi hooks flags -> do
generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
buildHook simpleUserHooks pkg lbi hooks flags
}
generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()
generateBuildModule verbosity pkg lbi = do
let dir = autogenModulesDir lbi
createDirectoryIfMissingVerbose verbosity True dir
withLibLBI pkg lbi $ \_ libcfg -> do
withTestLBI pkg lbi $ \suite suitecfg -> do
let testSuiteName = unUnqualComponentName (testName suite)
rewriteFile (dir </> "Build_" ++ testSuiteName ++ ".hs") $ unlines
[ "module Build_" ++ testSuiteName ++ " where"
, "deps :: [String]"
, "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))
]
where
formatdeps = map (formatone . snd)
formatone p =
unMungedPackageName (mungedName p) ++ "-" ++ showVersion (mungedVersion p)
testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, MungedPackageId)]
testDeps xs ys = ordNub $ componentPackageDeps xs ++ componentPackageDeps ys

2
pontarius-xmpp.cabal

@ -55,7 +55,7 @@ Library
, exceptions >=0.6 , exceptions >=0.6
, hslogger >=1.1.0 , hslogger >=1.1.0
, iproute >=1.2.4 , iproute >=1.2.4
, lens-family , lens-family < 2.0.0
, lifted-base >=0.1.0.1 , lifted-base >=0.1.0.1
, mtl >=2.0.0.0 , mtl >=2.0.0.0
, network >=2.3.1.0 , network >=2.3.1.0

32
source/Network/Xmpp/Concurrent.hs

@ -1,4 +1,4 @@
{-# LANGUAGE TupleSections #-} {-# LANGUAGE TupleSections #-}
{-# OPTIONS_HADDOCK hide #-} {-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Network.Xmpp.Concurrent module Network.Xmpp.Concurrent
@ -18,19 +18,19 @@ module Network.Xmpp.Concurrent
, simpleAuth , simpleAuth
) where ) where
import Control.Applicative ((<$>)) import Control.Applicative ((<$>))
import Control.Arrow (second) import Control.Arrow (second)
import Control.Concurrent (threadDelay) import Control.Concurrent (threadDelay)
import Control.Concurrent.STM import Control.Concurrent.STM
import qualified Control.Exception as Ex import qualified Control.Exception as Ex
import Control.Monad import Control.Monad
import Control.Monad.Except import Control.Monad.Except
import qualified Data.List as List import qualified Data.List as List
import qualified Data.Map as Map import qualified Data.Map as Map
import Data.Maybe import Data.Maybe
import Data.Text as Text import Data.Text as Text
import Data.XML.Types import Data.XML.Types
import Network import Network.Socket
import Network.Xmpp.Concurrent.Basic import Network.Xmpp.Concurrent.Basic
import Network.Xmpp.Concurrent.IQ import Network.Xmpp.Concurrent.IQ
import Network.Xmpp.Concurrent.Message import Network.Xmpp.Concurrent.Message
@ -38,17 +38,17 @@ import Network.Xmpp.Concurrent.Monad
import Network.Xmpp.Concurrent.Presence import Network.Xmpp.Concurrent.Presence
import Network.Xmpp.Concurrent.Threads import Network.Xmpp.Concurrent.Threads
import Network.Xmpp.Concurrent.Types import Network.Xmpp.Concurrent.Types
import Network.Xmpp.IM.Roster
import Network.Xmpp.IM.Roster.Types
import Network.Xmpp.IM.PresenceTracker import Network.Xmpp.IM.PresenceTracker
import Network.Xmpp.IM.PresenceTracker.Types import Network.Xmpp.IM.PresenceTracker.Types
import Network.Xmpp.IM.Roster
import Network.Xmpp.IM.Roster.Types
import Network.Xmpp.Sasl import Network.Xmpp.Sasl
import Network.Xmpp.Sasl.Types import Network.Xmpp.Sasl.Types
import Network.Xmpp.Stream import Network.Xmpp.Stream
import Network.Xmpp.Tls import Network.Xmpp.Tls
import Network.Xmpp.Types import Network.Xmpp.Types
import System.Log.Logger import System.Log.Logger
import System.Random (randomRIO) import System.Random (randomRIO)
import Control.Monad.State.Strict import Control.Monad.State.Strict
@ -73,7 +73,7 @@ toChan :: TChan (Annotated Stanza) -> StanzaHandler
toChan stanzaC _ sta as = do toChan stanzaC _ sta as = do
case sta of case sta of
XmppStanza s -> atomically $ writeTChan stanzaC (s, as) XmppStanza s -> atomically $ writeTChan stanzaC (s, as)
_ -> return () _ -> return ()
return [(sta, [])] return [(sta, [])]
handleIQ :: TVar IQHandlers handleIQ :: TVar IQHandlers
@ -180,7 +180,7 @@ newSession stream config realm mbSasl = runExceptT $ do
mbRos <- liftIO $ initialRoster config mbRos <- liftIO $ initialRoster config
return $ case mbRos of return $ case mbRos of
Nothing -> Roster Nothing Map.empty Nothing -> Roster Nothing Map.empty
Just r -> r Just r -> r
rosRef <- liftIO $ newTVarIO ros rosRef <- liftIO $ newTVarIO ros
peers <- liftIO . newTVarIO $ Peers Map.empty peers <- liftIO . newTVarIO $ Peers Map.empty
rew <- lift $ newTVarIO 60 rew <- lift $ newTVarIO 60
@ -243,7 +243,7 @@ connectStream :: HostName
connectStream realm config mbSasl = do connectStream realm config mbSasl = do
Ex.bracketOnError (openStream realm (sessionStreamConfiguration config)) Ex.bracketOnError (openStream realm (sessionStreamConfiguration config))
(\s -> case s of (\s -> case s of
Left _ -> return () Left _ -> return ()
Right stream -> closeStreams stream) Right stream -> closeStreams stream)
(\stream' -> case stream' of (\stream' -> case stream' of
@ -366,7 +366,7 @@ reconnect' sess = go 0
res <- doRetry sess res <- doRetry sess
case res of case res of
Nothing -> return i Nothing -> return i
Just _e -> go (i+1) Just _e -> go (i+1)
doRetry :: Session -> IO (Maybe XmppFailure) doRetry :: Session -> IO (Maybe XmppFailure)
doRetry sess@Session{reconnectWait = rw} = do doRetry sess@Session{reconnectWait = rw} = do

46
source/Network/Xmpp/Concurrent/Types.hs

@ -1,23 +1,23 @@
{-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ExistentialQuantification #-}
{-# OPTIONS_HADDOCK hide #-} {-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveDataTypeable #-}
module Network.Xmpp.Concurrent.Types where module Network.Xmpp.Concurrent.Types where
import Control.Concurrent import Control.Concurrent
import Control.Concurrent.STM import Control.Concurrent.STM
import qualified Control.Exception.Lifted as Ex import qualified Control.Exception.Lifted as Ex
import Control.Monad.Except import Control.Monad.Except
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import Data.Default import Data.Default
import qualified Data.Map as Map import qualified Data.Map as Map
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as Text import qualified Data.Text as Text
import Data.Typeable import Data.Typeable
import Data.XML.Types (Element) import Data.XML.Types (Element)
import Network import Network.Socket (HostName, PortNumber)
import Network.Xmpp.IM.Roster.Types
import Network.Xmpp.IM.PresenceTracker.Types import Network.Xmpp.IM.PresenceTracker.Types
import Network.Xmpp.IM.Roster.Types
import Network.Xmpp.Sasl.Types import Network.Xmpp.Sasl.Types
import Network.Xmpp.Types import Network.Xmpp.Types
@ -144,26 +144,26 @@ type WriteSemaphore = TMVar (BS.ByteString -> IO (Either XmppFailure ()))
-- | The Session object represents a single session with an XMPP server. You can -- | The Session object represents a single session with an XMPP server. You can
-- use 'session' to establish a session -- use 'session' to establish a session
data Session = Session data Session = Session
{ stanzaCh :: TChan (Stanza, [Annotation]) -- All stanzas { stanzaCh :: TChan (Stanza, [Annotation]) -- All stanzas
, iqHandlers :: TVar IQHandlers , iqHandlers :: TVar IQHandlers
-- Writing lock, so that only one thread could write to the stream at any -- Writing lock, so that only one thread could write to the stream at any
-- given time. -- given time.
-- Fields below are from Context. -- Fields below are from Context.
, writeSemaphore :: WriteSemaphore , writeSemaphore :: WriteSemaphore
, readerThread :: ThreadId , readerThread :: ThreadId
, idGenerator :: IO Text , idGenerator :: IO Text
-- | Lock (used by withStream) to make sure that a maximum of one -- | Lock (used by withStream) to make sure that a maximum of one
-- Stream action is executed at any given time. -- Stream action is executed at any given time.
, streamRef :: TMVar Stream , streamRef :: TMVar Stream
, eventHandlers :: TMVar EventHandlers , eventHandlers :: TMVar EventHandlers
, stopThreads :: IO () , stopThreads :: IO ()
, rosterRef :: TVar Roster , rosterRef :: TVar Roster
, presenceRef :: TVar Peers , presenceRef :: TVar Peers
, conf :: SessionConfiguration , conf :: SessionConfiguration
, sendStanza' :: Stanza -> IO (Either XmppFailure ()) , sendStanza' :: Stanza -> IO (Either XmppFailure ())
, sRealm :: HostName , sRealm :: HostName
, sSaslCredentials :: Maybe (ConnectionState -> [SaslHandler] , Maybe Text) , sSaslCredentials :: Maybe (ConnectionState -> [SaslHandler] , Maybe Text)
, reconnectWait :: TVar Int , reconnectWait :: TVar Int
} }
-- | IQHandlers holds the registered channels for incoming IQ requests and -- | IQHandlers holds the registered channels for incoming IQ requests and

20
source/Network/Xmpp/IM/PresenceTracker.hs

@ -5,17 +5,17 @@ import Control.Applicative
import Control.Concurrent import Control.Concurrent
import Control.Concurrent.STM import Control.Concurrent.STM
import Control.Monad import Control.Monad
import qualified Data.Foldable as Foldable import qualified Data.Foldable as Foldable
import Data.Map.Strict (Map) import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map import qualified Data.Map.Strict as Map
import Data.Maybe import Data.Maybe
import Lens.Family2 import Lens.Family2
import Lens.Family2.Stock import Lens.Family2.Stock
import Network.Xmpp.Concurrent.Types import Network.Xmpp.Concurrent.Types
import Network.Xmpp.IM.Presence import Network.Xmpp.IM.Presence
import Network.Xmpp.Lens hiding (Lens, Traversal) import Network.Xmpp.Lens hiding (Lens, Traversal)
import Network.Xmpp.Types import Network.Xmpp.Types
import Prelude hiding (mapM) import Prelude hiding (mapM)
import Network.Xmpp.IM.PresenceTracker.Types import Network.Xmpp.IM.PresenceTracker.Types
@ -26,26 +26,26 @@ _PeerAvailable :: Prism PeerStatus (Maybe IMPresence)
_PeerAvailable = prism' PeerAvailable fromPeerAvailable _PeerAvailable = prism' PeerAvailable fromPeerAvailable
where where
fromPeerAvailable (PeerAvailable pa) = Just pa fromPeerAvailable (PeerAvailable pa) = Just pa
fromPeerAvailable _ = Nothing fromPeerAvailable _ = Nothing
_PeerUnavailable :: Prism PeerStatus () _PeerUnavailable :: Prism PeerStatus ()
_PeerUnavailable = prism' (const PeerUnavailable) fromPeerUnavailable _PeerUnavailable = prism' (const PeerUnavailable) fromPeerUnavailable
where where
fromPeerUnavailable PeerUnavailable = Just () fromPeerUnavailable PeerUnavailable = Just ()
fromPeerUnavailable _ = Nothing fromPeerUnavailable _ = Nothing
_PeerStatus :: Iso (Maybe (Maybe IMPresence)) PeerStatus _PeerStatus :: Iso (Maybe (Maybe IMPresence)) PeerStatus
_PeerStatus = mkIso toPeerStatus fromPeerStatus _PeerStatus = mkIso toPeerStatus fromPeerStatus
where where
toPeerStatus (Nothing) = PeerUnavailable toPeerStatus (Nothing) = PeerUnavailable
toPeerStatus (Just imp) = PeerAvailable imp toPeerStatus (Just imp) = PeerAvailable imp
fromPeerStatus PeerUnavailable = Nothing fromPeerStatus PeerUnavailable = Nothing
fromPeerStatus (PeerAvailable imp) = Just imp fromPeerStatus (PeerAvailable imp) = Just imp
maybeMap :: Iso (Maybe (Map a b)) (Map a b) maybeMap :: Iso (Maybe (Map a b)) (Map a b)
maybeMap = mkIso maybeToMap mapToMaybe maybeMap = mkIso maybeToMap mapToMaybe
where where
maybeToMap Nothing = Map.empty maybeToMap Nothing = Map.empty
maybeToMap (Just m) = m maybeToMap (Just m) = m
mapToMaybe m | Map.null m = Nothing mapToMaybe m | Map.null m = Nothing
| otherwise = Just m | otherwise = Just m

120
source/Network/Xmpp/Stream.hs

@ -1,74 +1,73 @@
{-# OPTIONS_HADDOCK hide #-} {-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-}
{-# LANGUAGE FlexibleContexts #-}
module Network.Xmpp.Stream where module Network.Xmpp.Stream where
import Control.Applicative ((<$>)) import Control.Applicative ((<$>))
import Control.Concurrent (forkIO, threadDelay) import Control.Concurrent (forkIO, threadDelay)
import Control.Concurrent.STM import Control.Concurrent.STM
import qualified Control.Exception as Ex import qualified Control.Exception as Ex
import qualified Control.Exception.Lifted as ExL import qualified Control.Exception.Lifted as ExL
import Control.Monad import Control.Monad
import Control.Monad.Except import Control.Monad.Except
import Control.Monad.State.Strict import Control.Monad.State.Strict
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC8 import qualified Data.ByteString.Char8 as BSC8
import Data.Char (isSpace) import Data.Char (isSpace)
import Data.Conduit hiding (connect) import Data.Conduit hiding (connect)
import qualified Data.Conduit.Internal as DCI import qualified Data.Conduit.Internal as DCI
import qualified Data.Conduit.List as CL import qualified Data.Conduit.List as CL
import Data.IP import Data.IP
import Data.List import Data.List
import Data.Maybe import Data.Maybe
import Data.Ord import Data.Ord
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as Text import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text import qualified Data.Text.Encoding as Text
import qualified Data.Text.Encoding.Error as Text import qualified Data.Text.Encoding.Error as Text
import Data.Void (Void) import Data.Void (Void)
import Data.Word (Word16) import Data.Word (Word16)
import Data.XML.Pickle import Data.XML.Pickle
import Data.XML.Types import Data.XML.Types
import qualified GHC.IO.Exception as GIE import qualified GHC.IO.Exception as GIE
import Network import Network.DNS hiding (encode, lookup)
import Network.DNS hiding (encode, lookup) import Network.Socket (AddrInfo, HostName, PortNumber)
import qualified Network.Socket as S import qualified Network.Socket as S
import Network.Socket (AddrInfo)
import Network.Xmpp.Marshal import Network.Xmpp.Marshal
import Network.Xmpp.Types import Network.Xmpp.Types
import System.IO import System.IO
-- import System.IO.Error (tryIOError) <- Only available in base >=4.4 -- import System.IO.Error (tryIOError) <- Only available in base >=4.4
import Lens.Family2 (over)
import System.Log.Logger import System.Log.Logger
import System.Random (randomRIO) import System.Random (randomRIO)
import Text.XML.Stream.Parse as XP import Text.XML.Stream.Parse as XP
import Lens.Family2 (over)
import qualified Network.Xmpp.Lens as L
import Network.Xmpp.Utilities import Network.Xmpp.Utilities
import qualified Network.Xmpp.Lens as L
-- "readMaybe" definition, as readMaybe is not introduced in the `base' package -- "readMaybe" definition, as readMaybe is not introduced in the `base' package
-- until version 4.6. -- until version 4.6.
readMaybe_ :: (Read a) => String -> Maybe a readMaybe_ :: (Read a) => String -> Maybe a
readMaybe_ string = case reads string of readMaybe_ string = case reads string of
[(a, "")] -> Just a [(a, "")] -> Just a
_ -> Nothing _ -> Nothing
-- import Text.XML.Stream.Elements -- import Text.XML.Stream.Elements
mbl :: Maybe [a] -> [a] mbl :: Maybe [a] -> [a]
mbl (Just l) = l mbl (Just l) = l
mbl Nothing = [] mbl Nothing = []
lmb :: [t] -> Maybe [t] lmb :: [t] -> Maybe [t]
lmb [] = Nothing lmb [] = Nothing
lmb x = Just x lmb x = Just x
-- Unpickles and returns a stream element. -- Unpickles and returns a stream element.
streamUnpickleElem :: PU [Node] a streamUnpickleElem :: PU [Node] a
@ -90,9 +89,9 @@ throwOutJunk :: Monad m => ConduitM Event a m ()
throwOutJunk = do throwOutJunk = do
next <- CL.peek next <- CL.peek
case next of case next of
Nothing -> return () -- This will only happen if the stream is closed. Nothing -> return () -- This will only happen if the stream is closed.
Just (EventBeginElement _ _) -> return () Just (EventBeginElement _ _) -> return ()
_ -> CL.drop 1 >> throwOutJunk _ -> CL.drop 1 >> throwOutJunk
-- Returns an (empty) Element from a stream of XML events. -- Returns an (empty) Element from a stream of XML events.
openElementFromEvents :: StreamSink Element openElementFromEvents :: StreamSink Element
@ -117,12 +116,12 @@ startStream = runExceptT $ do
-- state of the stream. -- state of the stream.
let expectedTo = case ( streamConnectionState st let expectedTo = case ( streamConnectionState st
, toJid $ streamConfiguration st) of , toJid $ streamConfiguration st) of
(Plain , (Just (j, True))) -> Just j (Plain , (Just (j, True))) -> Just j
(Plain , _ ) -> Nothing (Plain , _ ) -> Nothing
(Secured , (Just (j, _ ))) -> Just j (Secured , (Just (j, _ ))) -> Just j
(Secured , Nothing ) -> Nothing (Secured , Nothing ) -> Nothing
(Closed , _ ) -> Nothing (Closed , _ ) -> Nothing
(Finished , _ ) -> Nothing (Finished , _ ) -> Nothing
case streamAddress st of case streamAddress st of
Nothing -> do Nothing -> do
lift $ lift $ errorM "Pontarius.Xmpp" "Server sent no hostname." lift $ lift $ errorM "Pontarius.Xmpp" "Server sent no hostname."
@ -216,7 +215,7 @@ startStream = runExceptT $ do
StreamBadFormat Nothing StreamBadFormat Nothing
"" ""
safeRead x = case reads $ Text.unpack x of safeRead x = case reads $ Text.unpack x of
[] -> Nothing [] -> Nothing
((y,_):_) -> Just y ((y,_):_) -> Just y
flattenAttrs :: [(Name, [Content])] -> [(Name, Text.Text)] flattenAttrs :: [(Name, [Content])] -> [(Name, Text.Text)]
@ -227,7 +226,7 @@ flattenAttrs attrs = Prelude.map (\(name, cont) ->
attrs attrs
where where
uncontentify (ContentText t) = t uncontentify (ContentText t) = t
uncontentify _ = "" uncontentify _ = ""
-- Sets a new Event source using the raw source (of bytes) -- Sets a new Event source using the raw source (of bytes)
-- and calls xmppStartStream. -- and calls xmppStartStream.
@ -249,7 +248,7 @@ sourceStreamHandleRaw s = forever . read $ streamReceive s
read rd = do read rd = do
bs' <- liftIO (rd 4096) bs' <- liftIO (rd 4096)
bs <- case bs' of bs <- case bs' of
Left e -> throwError e Left e -> throwError e
Right r -> return r Right r -> return r
yield bs yield bs
@ -300,8 +299,8 @@ bufferSrc src = do
return $ Right b return $ Right b
) )
case dt of case dt of
Left e -> throwError e Left e -> throwError e
Right Nothing -> return () Right Nothing -> return ()
Right (Just d) -> yield d >> go Right (Just d) -> yield d >> go
return go return go
where where
@ -335,7 +334,7 @@ streamS _expectedTo = do -- TODO: check expectedTo
el <- openElementFromEvents -- May throw `XmppOtherFailure' if an el <- openElementFromEvents -- May throw `XmppOtherFailure' if an
-- element is not received -- element is not received
case unpickleElem xpStream el of case unpickleElem xpStream el of
Left _ -> return $ Left el Left _ -> return $ Left el
Right r -> return $ Right r Right r -> return $ Right r
xmppStreamFeatures :: StreamSink StreamFeatures xmppStreamFeatures :: StreamSink StreamFeatures
xmppStreamFeatures = do xmppStreamFeatures = do
@ -431,7 +430,7 @@ nsHack e@(Element{elementName = n})
where where
mapNSHack :: Node -> Node mapNSHack :: Node -> Node
mapNSHack (NodeElement el) = NodeElement $ nsHack el mapNSHack (NodeElement el) = NodeElement $ nsHack el
mapNSHack nd = nd mapNSHack nd = nd
-- | Encode and send stanza -- | Encode and send stanza
pushStanza :: Stanza -> Stream -> IO (Either XmppFailure ()) pushStanza :: Stanza -> Stream -> IO (Either XmppFailure ())
@ -494,8 +493,8 @@ pullStanza :: Stream -> IO (Either XmppFailure Stanza)
pullStanza = withStream' $ do pullStanza = withStream' $ do
res <- pullUnpickle xpStreamStanza res <- pullUnpickle xpStreamStanza
case res of case res of
Left e -> return $ Left e Left e -> return $ Left e
Right (Left e) -> return $ Left $ StreamErrorFailure e Right (Left e) -> return $ Left $ StreamErrorFailure e
Right (Right r) -> return $ Right r Right (Right r) -> return $ Right r
-- | Pulls a stanza, nonza or stream error from the stream. -- | Pulls a stanza, nonza or stream error from the stream.
@ -503,8 +502,8 @@ pullXmppElement :: Stream -> IO (Either XmppFailure XmppElement)
pullXmppElement = withStream' $ do pullXmppElement = withStream' $ do
res <- pullUnpickle xpStreamElement res <- pullUnpickle xpStreamElement
case res of case res of
Left e -> return $ Left e Left e -> return $ Left e
Right (Left e) -> return $ Left $ StreamErrorFailure e Right (Left e) -> return $ Left $ StreamErrorFailure e
Right (Right r) -> return $ Right r Right (Right r) -> return $ Right r
-- Performs the given IO operation, catches any errors and re-throws everything -- Performs the given IO operation, catches any errors and re-throws everything
@ -515,7 +514,7 @@ catchPush p = ExL.catch
(\e -> case GIE.ioe_type e of (\e -> case GIE.ioe_type e of
GIE.ResourceVanished -> return . Left $ XmppIOException e GIE.ResourceVanished -> return . Left $ XmppIOException e
GIE.IllegalOperation -> return . Left $ XmppIOException e GIE.IllegalOperation -> return . Left $ XmppIOException e
_ -> ExL.throwIO e _ -> ExL.throwIO e
) )
zeroHandle :: StreamHandle zeroHandle :: StreamHandle
@ -594,7 +593,7 @@ createStream realm config = do
return d return d
tlsIdentL = L.tlsParamsL . L.clientServerIdentificationL tlsIdentL = L.tlsParamsL . L.clientServerIdentificationL
updateHost host ("", _) = (host, "") updateHost host ("", _) = (host, "")
updateHost _ hst = hst updateHost _ hst = hst
maybeSetTlsHost host = over tlsIdentL (updateHost host) maybeSetTlsHost host = over tlsIdentL (updateHost host)
-- Connects using the specified method. Returns the Handle acquired, if any. -- Connects using the specified method. Returns the Handle acquired, if any.
@ -655,12 +654,11 @@ connectSrv config host = do
throwError XmppIllegalTcpDetails throwError XmppIllegalTcpDetails
where for = flip fmap where for = flip fmap
showPort :: PortID -> String
#if MIN_VERSION_network(2, 4, 1) #if MIN_VERSION_network(2, 4, 1)
showPort = show showPort = show
#else #else
showPort (PortNumber x) = "PortNumber " ++ show x showPort (PortNumber x) = "PortNumber " ++ show x
showPort (Service x) = "Service " ++ show x showPort (Service x) = "Service " ++ show x
#if !defined(mingw32_HOST_OS) && !defined(__MINGW32__) #if !defined(mingw32_HOST_OS) && !defined(__MINGW32__)
showPort (UnixSocket x) = "UnixSocket " ++ show x showPort (UnixSocket x) = "UnixSocket " ++ show x
#endif #endif
@ -720,7 +718,7 @@ resolvSrvsAndConnectTcp ((domain, port):remaining) = do
result <- resolveAndConnectTcp domain port result <- resolveAndConnectTcp domain port
case result of case result of
Just handle -> return $ Just handle Just handle -> return $ Just handle
Nothing -> resolvSrvsAndConnectTcp remaining Nothing -> resolvSrvsAndConnectTcp remaining
-- The DNS functions may make error calls. This function catches any such -- The DNS functions may make error calls. This function catches any such
@ -759,7 +757,7 @@ srvLookup realm resolvSeed = ExceptT $ do
return Nothing return Nothing
case result of case result of
Right result' -> return $ Right result' Right result' -> return $ Right result'
Left e -> return $ Left $ XmppIOException e Left e -> return $ Left $ XmppIOException e
where where
-- This function orders the SRV result in accordance with RFC -- This function orders the SRV result in accordance with RFC
-- 2782. It sorts the SRV results in order of priority, and then -- 2782. It sorts the SRV results in order of priority, and then
@ -870,7 +868,7 @@ elements = do
go front = do go front = do
x <- f x <- f
case x of case x of
Left l -> return $ (l, front []) Left l -> return $ (l, front [])
Right r -> go (front . (:) r) Right r -> go (front . (:) r)
goE n as = do goE n as = do
(y, ns) <- many' goN (y, ns) <- many' goN
@ -897,7 +895,7 @@ elements = do
compressContents :: [Content] -> [Content] compressContents :: [Content] -> [Content]
compressContents cs = [ContentText $ Text.concat (map unwrap cs)] compressContents cs = [ContentText $ Text.concat (map unwrap cs)]
where unwrap (ContentText t) = t where unwrap (ContentText t) = t
unwrap (ContentEntity t) = t unwrap (ContentEntity t) = t
(><) f g (x, y) = (f x, g y) (><) f g (x, y) = (f x, g y)

20
source/Network/Xmpp/Types.hs

@ -11,6 +11,7 @@
{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_HADDOCK hide #-} {-# OPTIONS_HADDOCK hide #-}
{-# OPTIONS_GHC -Wno-deferred-type-errors #-}
module Network.Xmpp.Types module Network.Xmpp.Types
( NonemptyText(..) ( NonemptyText(..)
@ -108,9 +109,9 @@ import Language.Haskell.TH
import Language.Haskell.TH.Quote import Language.Haskell.TH.Quote
import qualified Language.Haskell.TH.Syntax as TH import qualified Language.Haskell.TH.Syntax as TH
#endif #endif
import Network
import Network.DNS import Network.DNS
import Network.TLS hiding (Version, HostName) import Network.Socket (HostName, PortNumber)
import Network.TLS hiding (HostName, Version)
import Network.TLS.Extra import Network.TLS.Extra
import qualified Text.StringPrep as SP import qualified Text.StringPrep as SP
import qualified Text.StringPrep.Profiles as SP import qualified Text.StringPrep.Profiles as SP
@ -945,9 +946,9 @@ jid = QuasiQuoter { quoteExp = \s -> do
case jidFromText t of case jidFromText t of
Nothing -> fail $ "Could not parse JID " ++ s Nothing -> fail $ "Could not parse JID " ++ s
Just j -> TH.lift j Just j -> TH.lift j
, quotePat = fail "Jid patterns aren't implemented" , quotePat = \_ -> fail "Jid patterns aren't implemented"
, quoteType = fail "jid QQ can't be used in type context" , quoteType = \_ -> fail "jid QQ can't be used in type context"
, quoteDec = fail "jid QQ can't be used in declaration context" , quoteDec = \_ -> fail "jid QQ can't be used in declaration context"
} }
-- | Synonym for 'jid' -- | Synonym for 'jid'
@ -1000,12 +1001,9 @@ langTagQ = QuasiQuoter {quoteExp = \s -> case langTagFromText $ Text.pack s of
map textE (subtags lt)) map textE (subtags lt))
|] |]
, quotePat = fail $ "LanguageTag patterns aren't" , quotePat = \_ -> fail "LanguageTag patterns aren't implemented"
++ " implemented" , quoteType = \_ -> fail "LanguageTag QQ can't be used in type context"
, quoteType = fail $ "LanguageTag QQ can't be used" , quoteDec = \_ -> fail "LanguageTag QQ can't be used in declaration context"
++ " in type context"
, quoteDec = fail $ "LanguageTag QQ can't be used"
++ " in declaration context"
} }
where where

12
stack.yaml

@ -1,18 +1,14 @@
resolver: lts-10.4 resolver: lts-17.14
packages: packages:
- examples/echoclient/ - examples/echoclient/
- '.' - '.'
extra-deps: extra-deps:
- ranges-0.2.4
- stringprep-1.0.0 - stringprep-1.0.0
- text-1.2.2.1 - lens-family-1.2.3
- xml-picklers-0.3.6 - lens-family-core-1.2.3
- conduit-1.3.0
- conduit-extra-1.3.0
- xml-conduit-1.8.0
- resourcet-1.2.0
flags: {} flags: {}

Loading…
Cancel
Save