|
|
|
@ -1,6 +1,6 @@ |
|
|
|
{-# LANGUAGE OverloadedStrings #-} |
|
|
|
{-# LANGUAGE OverloadedStrings #-} |
|
|
|
|
|
|
|
|
|
|
|
-- TODO: Allow the client to retry the bind with another resource |
|
|
|
{-# OPTIONS_HADDOCK hide #-} |
|
|
|
|
|
|
|
|
|
|
|
module Network.XMPP.Bind where |
|
|
|
module Network.XMPP.Bind where |
|
|
|
|
|
|
|
|
|
|
|
@ -13,35 +13,28 @@ import Network.XMPP.Types |
|
|
|
import Network.XMPP.Pickle |
|
|
|
import Network.XMPP.Pickle |
|
|
|
import Network.XMPP.Monad |
|
|
|
import Network.XMPP.Monad |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Produces a `bind' element, optionally wrapping a resource. |
|
|
|
-- A `bind' element. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bindP :: PU [Node] b -> PU [Node] b |
|
|
|
|
|
|
|
bindP c = xpElemNodes "{urn:ietf:params:xml:ns:xmpp-bind}bind" c |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- If the (optional resource) parameter is a `Just' value, a |
|
|
|
|
|
|
|
-- `resource' child element will be added to the `bind' element. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bindBody :: Maybe Text -> Element |
|
|
|
bindBody :: Maybe Text -> Element |
|
|
|
bindBody rsrc = (pickleElem |
|
|
|
bindBody = pickleElem $ |
|
|
|
(bindP . xpOption $ xpElemNodes "resource" (xpContent xpId)) |
|
|
|
-- Pickler to produce a |
|
|
|
rsrc |
|
|
|
-- "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>" |
|
|
|
) |
|
|
|
-- element, with a possible "<resource>[JID]</resource>" |
|
|
|
|
|
|
|
-- child. |
|
|
|
-- Extracts the character data in the `jid' element. |
|
|
|
bindP . xpOption $ xpElemNodes "resource" (xpContent xpId) |
|
|
|
|
|
|
|
|
|
|
|
jidP :: PU [Node] JID |
|
|
|
-- Sends a (synchronous) IQ set request for a (`Just') given or server-generated |
|
|
|
jidP = bindP $ xpElemNodes "jid" (xpContent xpPrim) |
|
|
|
-- resource and extract the JID from the non-error response. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Sends a (synchronous) IQ set request for a (`Just') given or |
|
|
|
|
|
|
|
-- server-generated resource and extract the JID from the non-error |
|
|
|
|
|
|
|
-- response. |
|
|
|
|
|
|
|
xmppBind :: Maybe Text -> XMPPConMonad Text |
|
|
|
xmppBind :: Maybe Text -> XMPPConMonad Text |
|
|
|
xmppBind rsrc = do |
|
|
|
xmppBind rsrc = do |
|
|
|
answer <- xmppSendIQ' "bind" Nothing Set Nothing (bindBody rsrc) |
|
|
|
answer <- xmppSendIQ' "bind" Nothing Set Nothing (bindBody rsrc) |
|
|
|
let (Right IQResult{iqResultPayload = Just b}) = answer -- TODO: Error handling |
|
|
|
let Right IQResult{iqResultPayload = Just b} = answer -- TODO: Error handling |
|
|
|
let Right (JID _n _d (Just r)) = unpickleElem jidP b |
|
|
|
let Right (JID _n _d (Just r)) = unpickleElem jidP b |
|
|
|
return r |
|
|
|
return r |
|
|
|
|
|
|
|
where |
|
|
|
|
|
|
|
-- Extracts the character data in the `jid' element. |
|
|
|
|
|
|
|
jidP :: PU [Node] JID |
|
|
|
|
|
|
|
jidP = bindP $ xpElemNodes "jid" (xpContent xpPrim) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- A `bind' element pickler. |
|
|
|
|
|
|
|
bindP :: PU [Node] b -> PU [Node] b |
|
|
|
|
|
|
|
bindP c = xpElemNodes "{urn:ietf:params:xml:ns:xmpp-bind}bind" c |