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.

80 lines
2.8 KiB

{-# Language OverloadedStrings, ViewPatterns, NoMonomorphismRestriction #-}
module Network.XMPP.Marshal where
import Control.Applicative((<$>))
import Data.Maybe
14 years ago
import Data.Text(Text)
import qualified Data.Text as Text
import Network.XMPP.Pickle
import Network.XMPP.Types
import Text.XML.Expat.Pickle
stanzaSel (SMessage _ )= 0
stanzaSel (SPresence _ )= 1
stanzaSel (SIQ _ )= 2
14 years ago
stanzaP :: PU [Node Text Text] Stanza
stanzaP = xpAlt stanzaSel
[ xpWrap (SMessage , (\(SMessage m) -> m)) messageP
, xpWrap (SPresence , (\(SPresence p) -> p)) presenceP
, xpWrap (SIQ , (\(SIQ i) -> i)) iqP
]
14 years ago
messageP :: PU [Node Text Text] Message
messageP = xpWrap ( (\((from, to, id, tp),(sub, body, thr,ext))
-> Message from to id tp sub body thr ext)
, (\(Message from to id tp sub body thr ext)
-> ((from, to, id, tp), (sub, body, thr,ext)))
) $
xpElem "message"
(xp4Tuple
(xpAttrImplied "from" xpPrim)
(xpAttr "to" xpPrim)
(xpAttrImplied "id" xpText)
(xpAttrImplied "type" xpPrim)
)
(xp4Tuple
(xpOption . xpElemNodes "subject" $ xpContent xpText)
(xpOption . xpElemNodes "body" $ xpContent xpText)
(xpOption . xpElemNodes "thread" $ xpContent xpText)
xpTrees
)
14 years ago
presenceP :: PU [Node Text Text] Presence
presenceP = xpWrap ( (\((from, to, id, tp),(shw, stat, prio, ext))
-> Presence from to id tp shw stat prio ext)
, (\(Presence from to id tp shw stat prio ext)
-> ((from, to, id, tp), (shw, stat, prio, ext)))
) $
xpElem "presence"
(xp4Tuple
(xpAttrImplied "from" xpPrim)
(xpAttrImplied "to" xpPrim)
(xpAttrImplied "id" xpText)
(xpAttrImplied "type" xpPrim)
)
(xp4Tuple
(xpOption . xpElemNodes "show" $ xpContent xpPrim)
(xpOption . xpElemNodes "status" $ xpContent xpText)
(xpOption . xpElemNodes "priority" $ xpContent xpPrim)
xpTrees
)
14 years ago
iqP :: PU [Node Text Text] IQ
iqP = xpWrap ( (\((from, to, id, tp),body) -> IQ from to id tp body)
, (\(IQ from to id tp body) -> ((from, to, id, tp), body))
) $
xpElem "iq"
(xp4Tuple
(xpAttrImplied "from" xpPrim)
(xpAttrImplied "to" xpPrim)
(xpAttr "id" xpText)
(xpAttr "type" xpPrim))
(xpTree)
14 years ago