From 047b03109b1e4b66bc308e806d4a92cdae344610 Mon Sep 17 00:00:00 2001 From: Philipp Balzarek Date: Thu, 19 Dec 2013 14:33:13 +0100 Subject: [PATCH] add mkStanzaError and export iqResult and associatedErrorType --- source/Network/Xmpp.hs | 5 ++++- source/Network/Xmpp/Stanza.hs | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/source/Network/Xmpp.hs b/source/Network/Xmpp.hs index 4c47c85..3b68c13 100644 --- a/source/Network/Xmpp.hs +++ b/source/Network/Xmpp.hs @@ -164,11 +164,14 @@ module Network.Xmpp , sendIQ , sendIQ' , answerIQ + , iqResult , listenIQChan , dropIQChan -- * Errors - , StanzaError(..) , StanzaErrorType(..) + , StanzaError(..) + , associatedErrorType + , mkStanzaError , StanzaErrorCondition(..) , SaslFailure(..) -- * Threads diff --git a/source/Network/Xmpp/Stanza.hs b/source/Network/Xmpp/Stanza.hs index 565f057..01aba86 100644 --- a/source/Network/Xmpp/Stanza.hs +++ b/source/Network/Xmpp/Stanza.hs @@ -56,14 +56,20 @@ answerMessage _ _ = Nothing presTo :: Presence -> Jid -> Presence presTo pres to' = pres{presenceTo = Just to'} +-- | Create a StanzaError with @condition@ and the 'associatedErrorType'. Leave +-- the error text and the application specific condition empty +mkStanzaError :: StanzaErrorCondition -- ^ condition + -> StanzaError +mkStanzaError condition = StanzaError (associatedErrorType condition) + condition Nothing Nothing + -- | Create an IQ error response to an IQ request using the given condition. The -- error type is derived from the condition using 'associatedErrorType' and -- both text and the application specific condition are left empty iqError :: StanzaErrorCondition -> IQRequest -> IQError iqError condition (IQRequest iqid from' _to lang' _tp _bd) = - IQError iqid Nothing from' lang' err Nothing - where - err = StanzaError (associatedErrorType condition) condition Nothing Nothing + IQError iqid Nothing from' lang' (mkStanzaError condition) Nothing + -- | Create an IQ Result matching an IQ request iqResult :: Maybe Element -> IQRequest -> IQResult @@ -82,7 +88,7 @@ iqResult pl iqr = IQResult -- -- * 'PolicyViolation': 'Modify' or 'Wait' ('Modify') -- --- * 'RemoteServerTimeout': Wait or unspecified other ('Wait') +-- * 'RemoteServerTimeout': 'Wait' or unspecified other ('Wait') -- -- * 'UndefinedCondition': Any condition ('Cancel') associatedErrorType :: StanzaErrorCondition -> StanzaErrorType