Browse Source

Send session element depending on stream features

Fixes #94
master
Philipp Balzarek 10 years ago
parent
commit
1030940ee6
  1. 2
      pontarius-xmpp.cabal
  2. 4
      source/Network/Xmpp/Concurrent.hs
  3. 5
      source/Network/Xmpp/Lens.hs
  4. 15
      source/Network/Xmpp/Marshal.hs
  5. 11
      source/Network/Xmpp/Sasl.hs
  6. 9
      source/Network/Xmpp/Types.hs

2
pontarius-xmpp.cabal

@ -48,7 +48,7 @@ Library
, cryptohash-cryptoapi >=0.1 , cryptohash-cryptoapi >=0.1
, data-default >=0.2 , data-default >=0.2
, dns >=0.3.0 , dns >=0.3.0
, 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

4
source/Network/Xmpp/Concurrent.hs

@ -207,8 +207,8 @@ newSession stream config realm mbSasl = runErrorT $ do
, sSaslCredentials = mbSasl , sSaslCredentials = mbSasl
, reconnectWait = rew , reconnectWait = rew
} }
liftIO . atomically $ putTMVar eh $ EventHandlers { connectionClosedHandler = liftIO . atomically $ putTMVar eh $
onConnectionClosed config sess } EventHandlers { connectionClosedHandler = onConnectionClosed config sess }
-- Pass the new session to the plugins so they can "tie the knot" -- 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

5
source/Network/Xmpp/Lens.hs

@ -83,7 +83,6 @@ module Network.Xmpp.Lens
, toJidL , toJidL
, connectionDetailsL , connectionDetailsL
, resolvConfL , resolvConfL
, establishSessionL
, tlsBehaviourL , tlsBehaviourL
, tlsParamsL , tlsParamsL
-- **** TLS parameters -- **** TLS parameters
@ -489,10 +488,6 @@ resolvConfL :: Lens StreamConfiguration ResolvConf
resolvConfL inj sc@StreamConfiguration{resolvConf = x} resolvConfL inj sc@StreamConfiguration{resolvConf = x}
= (\x' -> sc{resolvConf = x'}) <$> inj x = (\x' -> sc{resolvConf = x'}) <$> inj x
establishSessionL :: Lens StreamConfiguration Bool
establishSessionL inj sc@StreamConfiguration{establishSession = x}
= (\x' -> sc{establishSession = x'}) <$> inj x
tlsBehaviourL :: Lens StreamConfiguration TlsBehaviour tlsBehaviourL :: Lens StreamConfiguration TlsBehaviour
tlsBehaviourL inj sc@StreamConfiguration{tlsBehaviour = x} tlsBehaviourL inj sc@StreamConfiguration{tlsBehaviour = x}
= (\x' -> sc{tlsBehaviour = x'}) <$> inj x = (\x' -> sc{tlsBehaviour = x'}) <$> inj x

15
source/Network/Xmpp/Marshal.hs

@ -350,21 +350,22 @@ xpStream = xpElemAttrs
-- Pickler/Unpickler for the stream features - TLS, SASL, and the rest. -- Pickler/Unpickler for the stream features - TLS, SASL, and the rest.
xpStreamFeatures :: PU [Node] StreamFeatures xpStreamFeatures :: PU [Node] StreamFeatures
xpStreamFeatures = ("xpStreamFeatures","") <?> xpWrap xpStreamFeatures = ("xpStreamFeatures","") <?> xpWrap
(\(tls, sasl, ver, preAppr, rest) (\(tls, sasl, ver, preAppr, session, rest)
-> StreamFeatures tls (mbl sasl) ver preAppr rest) -> StreamFeatures tls (mbl sasl) ver preAppr session rest )
(\(StreamFeatures tls sasl ver preAppr rest) (\(StreamFeatures tls sasl ver preAppr session rest)
-> (tls, lmb sasl, ver, preAppr, rest)) -> (tls, lmb sasl, ver, preAppr, session, rest))
(xpElemNodes (xpElemNodes
(Name (Name
"features" "features"
(Just "http://etherx.jabber.org/streams") (Just "http://etherx.jabber.org/streams")
(Just "stream") (Just "stream")
) )
(xp5Tuple (xp6Tuple
(xpOption pickleTlsFeature) (xpOption pickleTlsFeature)
(xpOption pickleSaslFeature) (xpOption pickleSaslFeature)
(xpOption pickleRosterVer) (xpOption pickleRosterVer)
picklePreApproval picklePreApproval
(xpOption pickleSessionFeature)
(xpAll xpElemVerbatim) (xpAll xpElemVerbatim)
) )
) )
@ -381,6 +382,10 @@ xpStreamFeatures = ("xpStreamFeatures","") <?> xpWrap
pickleRosterVer = xpElemNodes "{urn:xmpp:features:rosterver}ver" $ pickleRosterVer = xpElemNodes "{urn:xmpp:features:rosterver}ver" $
xpElemExists "{urn:xmpp:features:rosterver}optional" xpElemExists "{urn:xmpp:features:rosterver}optional"
picklePreApproval = xpElemExists "{urn:xmpp:features:pre-approval}sub" picklePreApproval = xpElemExists "{urn:xmpp:features:pre-approval}sub"
pickleSessionFeature :: PU [Node] Bool
pickleSessionFeature = ("pickleSessionFeature", "") <?>
xpElemNodes "{urn:ietf:params:xml:ns:xmpp-session}session"
(xpElemExists "{urn:ietf:params:xml:ns:xmpp-session}optional")
xpJid :: PU Text Jid xpJid :: PU Text Jid

11
source/Network/Xmpp/Sasl.hs

@ -77,12 +77,19 @@ auth mechanisms resource con = runErrorT $ do
_jid <- ErrorT $ xmppBind resource con _jid <- ErrorT $ xmppBind resource con
ErrorT $ flip withStream' con $ do ErrorT $ flip withStream' con $ do
s <- get s <- get
case establishSession $ streamConfiguration s of
case sendStreamElement s of
False -> return $ Right Nothing False -> return $ Right Nothing
True -> do True -> do
_ <-liftIO $ startSession con _ <- liftIO $ startSession con
return $ Right Nothing return $ Right Nothing
f -> return f f -> return f
where
sendStreamElement s =
and [ -- Check that the stream feature is set and not optional
streamFeaturesSession (streamFeatures s) == Just False
]
-- Produces a `bind' element, optionally wrapping a resource. -- Produces a `bind' element, optionally wrapping a resource.
bindBody :: Maybe Text -> Element bindBody :: Maybe Text -> Element

9
source/Network/Xmpp/Types.hs

@ -727,6 +727,9 @@ data StreamFeatures = StreamFeatures
-- versioning and @Just True@ when the server sends the non-standard -- versioning and @Just True@ when the server sends the non-standard
-- "optional" element (observed with prosody). -- "optional" element (observed with prosody).
, streamFeaturesPreApproval :: !Bool -- ^ Does the server support pre-approval , streamFeaturesPreApproval :: !Bool -- ^ Does the server support pre-approval
, streamFeaturesSession :: !(Maybe Bool)
-- ^ Does this server allow the stream elelemt? (See
-- https://tools.ietf.org/html/draft-cridland-xmpp-session-01)
, streamFeaturesOther :: ![Element] , streamFeaturesOther :: ![Element]
-- TODO: All feature elements instead? -- TODO: All feature elements instead?
} deriving (Eq, Show) } deriving (Eq, Show)
@ -737,6 +740,7 @@ instance Monoid StreamFeatures where
, streamFeaturesMechanisms = [] , streamFeaturesMechanisms = []
, streamFeaturesRosterVer = Nothing , streamFeaturesRosterVer = Nothing
, streamFeaturesPreApproval = False , streamFeaturesPreApproval = False
, streamFeaturesSession = Nothing
, streamFeaturesOther = [] , streamFeaturesOther = []
} }
mappend sf1 sf2 = mappend sf1 sf2 =
@ -747,6 +751,7 @@ instance Monoid StreamFeatures where
, streamFeaturesPreApproval = , streamFeaturesPreApproval =
streamFeaturesPreApproval sf1 streamFeaturesPreApproval sf1
|| streamFeaturesPreApproval sf2 || streamFeaturesPreApproval sf2
, streamFeaturesSession = mplusOn streamFeaturesSession
, streamFeaturesOther = mplusOn streamFeaturesOther , streamFeaturesOther = mplusOn streamFeaturesOther
} }
@ -1245,8 +1250,6 @@ data StreamConfiguration =
-- | Whether or not to perform the legacy -- | Whether or not to perform the legacy
-- session bind as defined in the (outdated) -- session bind as defined in the (outdated)
-- RFC 3921 specification -- RFC 3921 specification
, establishSession :: Bool
-- | How the client should behave in regards to TLS.
, tlsBehaviour :: TlsBehaviour , tlsBehaviour :: TlsBehaviour
-- | Settings to be used for TLS negotitation -- | Settings to be used for TLS negotitation
, tlsParams :: ClientParams , tlsParams :: ClientParams
@ -1271,13 +1274,11 @@ xmppDefaultParams = (defaultParamsClient "" BS.empty)
} }
} }
instance Default StreamConfiguration where instance Default StreamConfiguration where
def = StreamConfiguration { preferredLang = Nothing def = StreamConfiguration { preferredLang = Nothing
, toJid = Nothing , toJid = Nothing
, connectionDetails = UseRealm , connectionDetails = UseRealm
, resolvConf = defaultResolvConf , resolvConf = defaultResolvConf
, establishSession = True
, tlsBehaviour = PreferTls , tlsBehaviour = PreferTls
, tlsParams = xmppDefaultParams , tlsParams = xmppDefaultParams
} }

Loading…
Cancel
Save