You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
|
14 years ago
|
{-# LANGUAGE OverloadedStrings #-}
|
||
|
|
|
||
|
14 years ago
|
{-# OPTIONS_HADDOCK hide #-}
|
||
|
14 years ago
|
|
||
|
14 years ago
|
module Network.XMPP.Bind where
|
||
|
|
|
||
|
|
import Data.Text as Text
|
||
|
|
|
||
|
14 years ago
|
import Data.XML.Pickle
|
||
|
|
import Data.XML.Types
|
||
|
|
|
||
|
14 years ago
|
import Network.XMPP.Types
|
||
|
14 years ago
|
import Network.XMPP.Pickle
|
||
|
14 years ago
|
import Network.XMPP.Monad
|
||
|
14 years ago
|
|
||
|
14 years ago
|
-- Produces a `bind' element, optionally wrapping a resource.
|
||
|
14 years ago
|
bindBody :: Maybe Text -> Element
|
||
|
14 years ago
|
bindBody = pickleElem $
|
||
|
|
-- Pickler to produce a
|
||
|
|
-- "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>"
|
||
|
|
-- element, with a possible "<resource>[JID]</resource>"
|
||
|
|
-- child.
|
||
|
14 years ago
|
xpBind . xpOption $ xpElemNodes "resource" (xpContent xpId)
|
||
|
14 years ago
|
|
||
|
|
-- Sends a (synchronous) IQ set request for a (`Just') given or server-generated
|
||
|
|
-- resource and extract the JID from the non-error response.
|
||
|
14 years ago
|
xmppBind :: Maybe Text -> XMPPConMonad Text
|
||
|
14 years ago
|
xmppBind rsrc = do
|
||
|
14 years ago
|
answer <- xmppSendIQ' "bind" Nothing Set Nothing (bindBody rsrc)
|
||
|
|
let Right IQResult{iqResultPayload = Just b} = answer -- TODO: Error handling
|
||
|
|
let Right (JID _n _d (Just r)) = unpickleElem jidP b
|
||
|
|
return r
|
||
|
|
where
|
||
|
|
-- Extracts the character data in the `jid' element.
|
||
|
|
jidP :: PU [Node] JID
|
||
|
14 years ago
|
jidP = xpBind $ xpElemNodes "jid" (xpContent xpPrim)
|
||
|
14 years ago
|
|
||
|
|
-- A `bind' element pickler.
|
||
|
14 years ago
|
xpBind :: PU [Node] b -> PU [Node] b
|
||
|
|
xpBind c = xpElemNodes "{urn:ietf:params:xml:ns:xmpp-bind}bind" c
|