|
|
|
@ -1,5 +1,7 @@ |
|
|
|
{-# LANGUAGE OverloadedStrings #-} |
|
|
|
{-# LANGUAGE OverloadedStrings #-} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- TODO: Allow the client to retry the bind with another resource |
|
|
|
|
|
|
|
|
|
|
|
module Network.XMPP.Bind where |
|
|
|
module Network.XMPP.Bind where |
|
|
|
|
|
|
|
|
|
|
|
import Data.Text as Text |
|
|
|
import Data.Text as Text |
|
|
|
@ -11,24 +13,36 @@ import Network.XMPP.Types |
|
|
|
import Network.XMPP.Pickle |
|
|
|
import Network.XMPP.Pickle |
|
|
|
import Network.XMPP.Concurrent |
|
|
|
import Network.XMPP.Concurrent |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- A `bind' element. |
|
|
|
|
|
|
|
|
|
|
|
bindP :: PU [Node] b -> PU [Node] b |
|
|
|
bindP :: PU [Node] b -> PU [Node] b |
|
|
|
bindP c = xpElemNodes "{urn:ietf:params:xml:ns:xmpp-bind}bind" c |
|
|
|
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 rsrc = (pickleElem |
|
|
|
(bindP . xpOption $ xpElemNodes "resource" (xpContent xpId)) |
|
|
|
(bindP . xpOption $ xpElemNodes "resource" (xpContent xpId)) |
|
|
|
rsrc |
|
|
|
rsrc |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Extracts the character data in the `jid' element. |
|
|
|
|
|
|
|
|
|
|
|
jidP :: PU [Node] JID |
|
|
|
jidP :: PU [Node] JID |
|
|
|
jidP = bindP $ xpElemNodes "jid" (xpContent xpPrim) |
|
|
|
jidP = bindP $ xpElemNodes "jid" (xpContent xpPrim) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Sends a (synchronous) IQ set request for a (`Just') given or |
|
|
|
|
|
|
|
-- server-generated resource and extract the JID from the non-error |
|
|
|
|
|
|
|
-- response. |
|
|
|
|
|
|
|
|
|
|
|
xmppThreadedBind :: Maybe Text -> XMPPThread Text |
|
|
|
xmppThreadedBind :: Maybe Text -> XMPPThread Text |
|
|
|
xmppThreadedBind rsrc = do |
|
|
|
xmppThreadedBind rsrc = do |
|
|
|
answer <- sendIQ' Nothing Set Nothing (bindBody rsrc) |
|
|
|
answer <- sendIQ' 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 (JID _n _d (Just r)) = unpickleElem jidP b |
|
|
|
let (JID _n _d (Just r)) = unpickleElem jidP b |
|
|
|
return r |
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|