From f21c94b205eebe01b7b0fe1c92a4f480c1ac912d Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 11 Nov 2015 14:56:05 +0100 Subject: [PATCH] core (client): added a sendError method to easily build error response from stanza --- src/core/sat_main.py | 1 + src/core/xmpp.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/core/sat_main.py b/src/core/sat_main.py index c8b54e09..a8273dff 100644 --- a/src/core/sat_main.py +++ b/src/core/sat_main.py @@ -478,6 +478,7 @@ class SAT(service.Service): def getJidNStream(self, profile_key): """Convenient method to get jid and stream from profile key @return: tuple (jid, xmlstream) from profile, can be None""" + # TODO: deprecate this method (getClient is enough) profile = self.memory.getProfileName(profile_key) if not profile or not self.profiles[profile].isConnected(): return (None, None) diff --git a/src/core/xmpp.py b/src/core/xmpp.py index 86d4c70c..bf22fa56 100644 --- a/src/core/xmpp.py +++ b/src/core/xmpp.py @@ -21,6 +21,7 @@ from sat.core.i18n import _ from sat.core.constants import Const as C from twisted.internet import task, defer from twisted.words.protocols.jabber import jid, xmlstream +from twisted.words.protocols.jabber import error from wokkel import client, disco, xmppim, generic, delay, iwokkel from sat.core.log import getLogger log = getLogger(__name__) @@ -59,6 +60,15 @@ class SatXMPPClient(client.XMPPClient): iq_elt.timeout = timeout return iq_elt + def sendError(self, iq_elt, condition): + """Send error stanza build from iq_elt + + @param iq_elt(domish.Element): initial IQ element + @param condition(unicode): error condition + """ + iq_error_elt = error.StanzaError(condition).toResponse(iq_elt) + self.xmlstream.send(iq_error_elt) + def _authd(self, xmlstream): if not self.host_app.trigger.point("XML Initialized", xmlstream, self.profile): return