|
|
|
@ -40,6 +40,8 @@ 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 |
|
|
|
import Network.Xmpp.IM.Roster.Types |
|
|
|
import Network.Xmpp.IM.Roster.Types |
|
|
|
|
|
|
|
import Network.Xmpp.IM.PresenceTracker |
|
|
|
|
|
|
|
import Network.Xmpp.IM.PresenceTracker.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 |
|
|
|
@ -165,30 +167,37 @@ newSession stream config realm mbSasl = runErrorT $ do |
|
|
|
iqHands <- lift $ newTVarIO (Map.empty, Map.empty) |
|
|
|
iqHands <- lift $ newTVarIO (Map.empty, Map.empty) |
|
|
|
eh <- lift $ newEmptyTMVarIO |
|
|
|
eh <- lift $ newEmptyTMVarIO |
|
|
|
ros <- liftIO . newTVarIO $ Roster Nothing Map.empty |
|
|
|
ros <- liftIO . newTVarIO $ Roster Nothing Map.empty |
|
|
|
|
|
|
|
peers <- liftIO . newTVarIO $ Peers Map.empty |
|
|
|
rew <- lift $ newTVarIO 60 |
|
|
|
rew <- lift $ newTVarIO 60 |
|
|
|
let out = writeStanza writeSem |
|
|
|
let out = writeStanza writeSem |
|
|
|
let rosterH = if (enableRoster config) then [handleRoster ros out] |
|
|
|
let rosterH = if (enableRoster config) then [handleRoster ros out] |
|
|
|
else [] |
|
|
|
else [] |
|
|
|
|
|
|
|
let presenceH = if (enablePresenceTracking config) |
|
|
|
|
|
|
|
then [handlePresence peers out] |
|
|
|
|
|
|
|
else [] |
|
|
|
(sStanza, ps) <- initPlugins out $ plugins config |
|
|
|
(sStanza, ps) <- initPlugins out $ plugins config |
|
|
|
let stanzaHandler = runHandlers $ List.concat |
|
|
|
let stanzaHandler = runHandlers $ List.concat |
|
|
|
[ inHandler <$> ps |
|
|
|
[ inHandler <$> ps |
|
|
|
, [ toChan stanzaChan sStanza |
|
|
|
, [ toChan stanzaChan sStanza |
|
|
|
, handleIQ iqHands sStanza |
|
|
|
, handleIQ iqHands sStanza |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
, presenceH |
|
|
|
, rosterH |
|
|
|
, rosterH |
|
|
|
] |
|
|
|
] |
|
|
|
(kill, streamState, reader) <- ErrorT $ startThreadsWith writeSem stanzaHandler eh stream |
|
|
|
(kill, sState, reader) <- ErrorT $ startThreadsWith writeSem stanzaHandler |
|
|
|
|
|
|
|
eh stream |
|
|
|
idGen <- liftIO $ sessionStanzaIDs config |
|
|
|
idGen <- liftIO $ sessionStanzaIDs config |
|
|
|
let sess = Session { stanzaCh = stanzaChan |
|
|
|
let sess = Session { stanzaCh = stanzaChan |
|
|
|
, iqHandlers = iqHands |
|
|
|
, iqHandlers = iqHands |
|
|
|
, writeSemaphore = writeSem |
|
|
|
, writeSemaphore = writeSem |
|
|
|
, readerThread = reader |
|
|
|
, readerThread = reader |
|
|
|
, idGenerator = idGen |
|
|
|
, idGenerator = idGen |
|
|
|
, streamRef = streamState |
|
|
|
, streamRef = sState |
|
|
|
, eventHandlers = eh |
|
|
|
, eventHandlers = eh |
|
|
|
, stopThreads = kill |
|
|
|
, stopThreads = kill |
|
|
|
, conf = config |
|
|
|
, conf = config |
|
|
|
, rosterRef = ros |
|
|
|
, rosterRef = ros |
|
|
|
|
|
|
|
, presenceRef = peers |
|
|
|
, sendStanza' = sStanza |
|
|
|
, sendStanza' = sStanza |
|
|
|
, sRealm = realm |
|
|
|
, sRealm = realm |
|
|
|
, sSaslCredentials = mbSasl |
|
|
|
, sSaslCredentials = mbSasl |
|
|
|
@ -196,9 +205,11 @@ newSession stream config realm mbSasl = runErrorT $ do |
|
|
|
} |
|
|
|
} |
|
|
|
liftIO . atomically $ putTMVar eh $ EventHandlers { connectionClosedHandler = |
|
|
|
liftIO . atomically $ putTMVar eh $ EventHandlers { connectionClosedHandler = |
|
|
|
onConnectionClosed config sess } |
|
|
|
onConnectionClosed config sess } |
|
|
|
|
|
|
|
-- Pass the new session to the plugins so they can "tie the knot" |
|
|
|
liftIO . forM_ ps $ \p -> onSessionUp p sess |
|
|
|
liftIO . forM_ ps $ \p -> onSessionUp p sess |
|
|
|
return sess |
|
|
|
return sess |
|
|
|
where |
|
|
|
where |
|
|
|
|
|
|
|
-- Pass the stanza out action to each plugin |
|
|
|
initPlugins out' = go out' [] |
|
|
|
initPlugins out' = go out' [] |
|
|
|
where |
|
|
|
where |
|
|
|
go out ps' [] = return (out, ps') |
|
|
|
go out ps' [] = return (out, ps') |
|
|
|
@ -269,8 +280,6 @@ simpleAuth uname pwd = Just (\cstate -> |
|
|
|
else [] |
|
|
|
else [] |
|
|
|
, Nothing) |
|
|
|
, Nothing) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- | Reconnect immediately with the stored settings. Returns @Just@ the error |
|
|
|
-- | Reconnect immediately with the stored settings. Returns @Just@ the error |
|
|
|
-- when the reconnect attempt fails and Nothing when no failure was encountered. |
|
|
|
-- when the reconnect attempt fails and Nothing when no failure was encountered. |
|
|
|
-- |
|
|
|
-- |
|
|
|
|