def error(failure): if failure.check(StanzaError): exc = failure.value else: log.err(failure) exc = StanzaError('internal-error') return exc.toResponse(iq)
def _cb_message_insert_done (self, _none, element, ) : # remove message file _file = os.path.join( self.parent._file_directory, xpath.queryForNodes("/message/x/file", element, )[0].__str__(), ) os.remove(_file, ) # send return message _q = xmppim.Query(element["from"], ) _q["id"] = element["id"] if isinstance(_none, Failure, ) : _error = StanzaError( "bad-request", #text=_none.getTraceback(), ) from flaskon.app.io._exceptions import AlreadyImported if _none.check(AlreadyImported, ) : _error.type = "already-imported" del _q.children[_q.children.index(_q._element_x, ) - 1] _element_x = domish.Element((xmppim.Query.XMLNS, "x"), ) _e = _error.toResponse(_element_x, ) _e.defaultUri = _e.uri = xmppim.Query.XMLNS _q.addChild(_e, ) else : _q._element_x["type"] = "success" self.send(_q, )
def onFrame(self, iq): jid = toJID(iq['from']) neighbor = self._findNeighbor(jid) if neighbor: neighbor.onFrame(iq) else: iq.handled = True error = StanzaError('not-authorized') self.send(error.toResponse(iq))
def onFeed(self, iq): handle = str(iq.aggregator.feed.handle or '') url = str(iq.aggregator.feed.url or '') iq.handled = True def success(_): return xmlstream.toResponse(iq, 'result') def trapInvalidHandle(failure): failure.trap(InvalidHandleError) raise StanzaError('bad-request', text='Invalid handle') def error(failure): if failure.check(StanzaError): exc = failure.value else: log.err(failure) exc = StanzaError('internal-error') return exc.toResponse(iq) if handle and url: d = self.service.setFeed(handle, url) d.addCallback(success) d.addErrback(trapInvalidHandle) else: d = defer.fail(StanzaError('bad-request')) d.addErrback(error) d.addCallback(self.send)
def test_pingNotSupported(self): """ Pinging a service should fire a deferred with None if not supported. """ def cb(result): self.assertIdentical(None, result) d = self.protocol.ping(JID("example.com")) d.addCallback(cb) iq = self.stub.output[-1] exc = StanzaError('service-unavailable') response = exc.toResponse(iq) self.stub.send(response) return d
def onFrame(self, iq): iq.handled = True frame = Frame.from_dom(iq) if frame.seq != self.in_seq_recv + 1: log.warning("Ignoring out-of-sequence frame from %s", self.jid.full()) error = StanzaError('bad-request') self.link.send(error.toResponse(iq)) return # ACK self.in_buf.append(frame) self.in_seq_recv += 1 self.link.send(toResponse(iq, 'result')) if not frame.more: self._do_recv()
def test_pingStanzaError(self): """ Pinging a service should errback a deferred on other (stanza) errors. """ def cb(exc): self.assertEquals('item-not-found', exc.condition) d = self.protocol.ping(JID("example.com")) self.assertFailure(d, StanzaError) d.addCallback(cb) iq = self.stub.output[-1] exc = StanzaError('item-not-found') response = exc.toResponse(iq) self.stub.send(response) return d
def info(self, requestor, target, nodeIdentifier): """ Gather data for a disco info request. @param requestor: The entity that sent the request. @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>} @param target: The entity the request was sent to. @type target: L{JID<twisted.words.protocols.jabber.jid.JID>} @param nodeIdentifier: The optional node being queried, or C{''}. @type nodeIdentifier: C{unicode} @return: Deferred with the gathered results from sibling handlers. @rtype: L{defer.Deferred} """ xmpp_manager = self.parent.manager if target.host not in xmpp_manager.domains | xmpp_manager.muc_domains: return defer.fail(StanzaError('service-unavailable')) elements = [disco.DiscoFeature(disco.NS_DISCO_INFO), disco.DiscoFeature(disco.NS_DISCO_ITEMS), disco.DiscoFeature('http://sylkserver.com')] if target.host in xmpp_manager.muc_domains: elements.append(disco.DiscoIdentity('conference', 'text', 'SylkServer Chat Service')) elements.append(disco.DiscoFeature('http://jabber.org/protocol/muc')) elements.append(disco.DiscoFeature('urn:ietf:rfc:3264')) elements.append(disco.DiscoFeature('urn:xmpp:coin')) elements.append(disco.DiscoFeature(jingle.NS_JINGLE)) elements.append(disco.DiscoFeature(jingle.NS_JINGLE_APPS_RTP)) elements.append(disco.DiscoFeature(jingle.NS_JINGLE_APPS_RTP_AUDIO)) #elements.append(disco.DiscoFeature(jingle.NS_JINGLE_APPS_RTP_VIDEO)) elements.append(disco.DiscoFeature(jingle.NS_JINGLE_ICE_UDP_TRANSPORT)) elements.append(disco.DiscoFeature(jingle.NS_JINGLE_RAW_UDP_TRANSPORT)) if target.user: # We can't say much more here, because the actual conference may end up on a different server elements.append(disco.DiscoFeature('muc_temporary')) elements.append(disco.DiscoFeature('muc_unmoderated')) else: elements.append(disco.DiscoFeature(ping.NS_PING)) if not target.user: elements.append(disco.DiscoIdentity('gateway', 'simple', 'SylkServer')) elements.append(disco.DiscoIdentity('server', 'im', 'SylkServer')) else: elements.append(disco.DiscoIdentity('client', 'pc')) elements.append(disco.DiscoFeature('http://jabber.org/protocol/caps')) elements.append(disco.DiscoFeature('http://jabber.org/protocol/chatstates')) elements.append(disco.DiscoFeature('urn:ietf:rfc:3264')) elements.append(disco.DiscoFeature('urn:xmpp:coin')) elements.append(disco.DiscoFeature(jingle.NS_JINGLE)) elements.append(disco.DiscoFeature(jingle.NS_JINGLE_APPS_RTP)) elements.append(disco.DiscoFeature(jingle.NS_JINGLE_APPS_RTP_AUDIO)) #elements.append(disco.DiscoFeature(jingle.NS_JINGLE_APPS_RTP_VIDEO)) elements.append(disco.DiscoFeature(jingle.NS_JINGLE_ICE_UDP_TRANSPORT)) elements.append(disco.DiscoFeature(jingle.NS_JINGLE_RAW_UDP_TRANSPORT)) return defer.succeed(elements)
def _mapErrors(self, failure): e = failure.trap(*self._errorMap.keys()) condition, pubsubCondition, feature = self._errorMap[e] msg = failure.value.msg if pubsubCondition: exc = PubSubError(condition, pubsubCondition, feature, msg) else: exc = StanzaError(condition, text=msg) raise exc
def trapInvalidHandle(failure): failure.trap(InvalidHandleError) raise StanzaError('bad-request', text='Invalid handle')