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.

42 lines
982 B

{-# LANGUAGE OverloadedStrings #-}
14 years ago
module Network.XMPP.Bind where
import Control.Monad.Trans.State
import Data.Text as Text
14 years ago
import Data.XML.Pickle
import Data.XML.Types
14 years ago
import Network.XMPP.Monad
import Network.XMPP.Types
import Network.XMPP.Pickle
14 years ago
import Network.XMPP.Marshal
14 years ago
14 years ago
bindReqIQ :: Maybe Text -> Stanza
bindReqIQ resource= SIQ $ IQ Nothing Nothing "bind" Set
(pickleElem
(bindP . xpOption
14 years ago
$ xpElemNodes "resource" (xpContent xpId))
resource
)
14 years ago
14 years ago
jidP :: PU [Node] JID
jidP = bindP $ xpElemNodes "jid" (xpContent xpPrim)
14 years ago
xmppBind :: Maybe Text -> XMPPMonad ()
xmppBind res = do
push $ bindReqIQ res
answer <- pull
let SIQ (IQ Nothing Nothing _ Result b) = answer
let (JID n d (Just r)) = unpickleElem jidP b
14 years ago
modify (\s -> s{sResource = Just r})
14 years ago
bindP :: PU [Node] b -> PU [Node] b
bindP c = xpElemNodes "{urn:ietf:params:xml:ns:xmpp-bind}bind" c
14 years ago