# Slixmpp: The Slick XMPP Library# Copyright (C) 2015 Emmanuel Gil Peyrot# This file is part of Slixmpp.# See the file LICENSE for copying permission.importasyncioimportloggingfromuuidimportuuid4fromslixmpp.pluginsimportBasePluginfromslixmppimportIq,Messagefromslixmpp.jidimportJIDfromslixmpp.xmlstreamimportregister_stanza_pluginfromslixmpp.xmlstream.handlerimportCallbackfromslixmpp.xmlstream.matcherimportStanzaPathfromslixmpp.plugins.xep_0070importstanza,Confirmlog=logging.getLogger(__name__)
[docs]classXEP_0070(BasePlugin):""" XEP-0070 Verifying HTTP Requests via XMPP """name='xep_0070'description='XEP-0070: Verifying HTTP Requests via XMPP'dependencies={'xep_0030'}stanza=stanzadefplugin_init(self):register_stanza_plugin(Iq,Confirm)register_stanza_plugin(Message,Confirm)self.xmpp.register_handler(Callback('Confirm',StanzaPath('iq@type=get/confirm'),self._handle_iq_confirm))self.xmpp.register_handler(Callback('Confirm',StanzaPath('message/confirm'),self._handle_message_confirm))defplugin_end(self):self.xmpp.remove_handler('Confirm')self.xmpp['xep_0030'].del_feature(feature='http://jabber.org/protocol/http-auth')defsession_bind(self,jid):self.xmpp['xep_0030'].add_feature('http://jabber.org/protocol/http-auth')defask_confirm(self,jid,id,url,method,*,ifrom=None,message=None):jid=JID(jid)ifjid.resource:stanza=self.xmpp.Iq()stanza['type']='get'else:stanza=self.xmpp.Message()stanza['thread']=uuid4().hexstanza['from']=ifromstanza['to']=jidstanza['confirm']['id']=idstanza['confirm']['url']=urlstanza['confirm']['method']=methodifnotjid.resource:ifmessageisnotNone:stanza['body']=message.format(id=id,url=url,method=method)stanza.send()fut=asyncio.Future()fut.set_result(stanza)returnfutelse:returnstanza.send()def_handle_iq_confirm(self,iq):self.xmpp.event('http_confirm_iq',iq)self.xmpp.event('http_confirm',iq)def_handle_message_confirm(self,message):self.xmpp.event('http_confirm_message',message)self.xmpp.event('http_confirm',message)