{-# LANGUAGE OverloadedStrings #-} module EventUtil where import Control.Monad import Data.XML.Types as XML import qualified Data.List as List getStreamName (EventBeginElement name _) = name isEventBeginElement (EventBeginElement {}) = True isEventBeginElement _ = False isEventEndElement (EventEndElement {}) = True isEventEndElement _ = False -- Note: This function ignores name space qualification elementAttrs expected (EventBeginElement name attrs) | nameLocalName name==expected = return attrs elementAttrs _ _ = mzero streamP name = Name name (Just "http://etherx.jabber.org/streams") (Just "stream") attr name value = (name,[ContentText value]) isServerIQOf (EventBeginElement name attrs) testType | name=="{jabber:server}iq" && matchAttrib "type" testType attrs = True isServerIQOf _ _ = False matchAttrib name value attrs = case List.find ( (==name) . fst) attrs of Just (_,[ContentText x]) | x==value -> True Just (_,[ContentEntity x]) | x==value -> True _ -> False lookupAttrib name attrs = case List.find ( (==name) . fst) attrs of Just (_,[ContentText x]) -> Just x Just (_,[ContentEntity x]) -> Just x _ -> Nothing tagAttrs (EventBeginElement _ xs) = xs tagAttrs _ = [] {- iqTypeSet = "set" iqTypeGet = "get" iqTypeResult = "result" iqTypeError = "error" -} tagName (EventBeginElement n _) = n tagName _ = "" closerFor (EventBeginElement n _) = EventEndElement n closerFor _ = error "closerFor: unsupported event"