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.

82 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)
14 years ago
import Data.XML.Types
import Data.XML.Pickle
import qualified Data.Text as Text
import Network.XMPP.Pickle
import Network.XMPP.Types
14 years ago
stanzaSel (SMessage _) = 0
stanzaSel (SPresence _) = 1
stanzaSel (SIQ _) = 2
14 years ago
stanzaP :: PU [Node] Stanza
stanzaP = xpAlt stanzaSel
14 years ago
[ xpWrap SMessage (\(SMessage m) -> m) messageP
, xpWrap SPresence (\(SPresence p) -> p) presenceP
, xpWrap SIQ (\(SIQ i) -> i) iqP
]
14 years ago
messageP :: PU [Node] Message
messageP = xpWrap (\((from, to, id, tp),(sub, body, thr,ext))
-> Message from to id tp sub body thr ext)
14 years ago
(\(Message from to id tp sub body thr ext)
-> ((from, to, id, tp), (sub, body, thr,ext)))
14 years ago
$
xpElem "message"
(xp4Tuple
(xpAttrImplied "from" xpPrim)
(xpAttr "to" xpPrim)
14 years ago
(xpAttrImplied "id" xpId)
(xpAttrImplied "type" xpPrim)
)
(xp4Tuple
14 years ago
(xpOption . xpElemNodes "subject" $ xpContent xpId)
(xpOption . xpElemNodes "body" $ xpContent xpId)
(xpOption . xpElemNodes "thread" $ xpContent xpId)
(xpAll xpElemVerbatim)
)
14 years ago
presenceP :: PU [Node] Presence
presenceP = xpWrap (\((from, to, id, tp),(shw, stat, prio, ext))
-> Presence from to id tp shw stat prio ext)
14 years ago
(\(Presence from to id tp shw stat prio ext)
-> ((from, to, id, tp), (shw, stat, prio, ext)))
14 years ago
$
xpElem "presence"
(xp4Tuple
(xpAttrImplied "from" xpPrim)
(xpAttrImplied "to" xpPrim)
14 years ago
(xpAttrImplied "id" xpId)
(xpAttrImplied "type" xpPrim)
)
(xp4Tuple
(xpOption . xpElemNodes "show" $ xpContent xpPrim)
14 years ago
(xpOption . xpElemNodes "status" $ xpContent xpId)
(xpOption . xpElemNodes "priority" $ xpContent xpPrim)
14 years ago
(xpAll xpElemVerbatim)
)
14 years ago
iqP :: PU [Node] 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)
14 years ago
(xpAttr "id" xpId)
(xpAttr "type" xpPrim))
14 years ago
(xpElemVerbatim)
14 years ago