Use nbxmpp properties for HTTPAuth

nbxmpp implements HTTPAuth now, so we dont need to parse it anymore
This commit is contained in:
Philipp Hörist 2018-12-21 12:23:26 +01:00
parent 42c1909d3b
commit 85e79e7b27
3 changed files with 20 additions and 27 deletions

View File

@ -420,7 +420,11 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
app.nec.push_incoming_event(IqErrorReceivedEvent(None, conn=self,
stanza=iq_obj))
def _IqCB(self, con, iq_obj):
def _IqCB(self, con, iq_obj, properties):
if properties.is_http_auth:
self.get_module('HTTPAuth').delegate(iq_obj, properties)
raise nbxmpp.NodeProcessed
id_ = iq_obj.getID()
app.nec.push_incoming_event(NetworkEvent('raw-iq-received',

View File

@ -19,7 +19,7 @@ import logging
import nbxmpp
from gajim.common import app
from gajim.common.nec import NetworkIncomingEvent
from gajim.common.nec import NetworkEvent
log = logging.getLogger('gajim.c.m.http_auth')
@ -29,12 +29,9 @@ class HTTPAuth:
self._con = con
self._account = con.name
self.handlers = [
('iq', self.answer_request, 'get', nbxmpp.NS_HTTP_AUTH),
('message', self.answer_request, '', nbxmpp.NS_HTTP_AUTH)
]
self.handlers = []
def answer_request(self, _con, stanza):
def delegate(self, stanza, properties):
log.info('Auth request received')
auto_answer = app.config.get_per(
'accounts', self._account, 'http_auth')
@ -42,22 +39,15 @@ class HTTPAuth:
self.build_http_auth_answer(stanza, auto_answer)
raise nbxmpp.NodeProcessed
iq_id = stanza.getTagAttr('confirm', 'id')
method = stanza.getTagAttr('confirm', 'method')
url = stanza.getTagAttr('confirm', 'url')
# In case it's a message with a body
msg = stanza.getTagData('body')
app.nec.push_incoming_event(
HttpAuthReceivedEvent(None, conn=self._con,
iq_id=iq_id,
method=method,
url=url,
msg=msg,
NetworkEvent('http-auth-received',
conn=self._con,
iq_id=properties['id'],
method=properties['method'],
url=properties['url'],
msg=properties['body'],
stanza=stanza))
raise nbxmpp.NodeProcessed
def build_http_auth_answer(self, stanza, answer):
if answer == 'yes':
log.info('Auth request approved')
@ -72,9 +62,5 @@ class HTTPAuth:
self._con.connection.send(err)
class HttpAuthReceivedEvent(NetworkIncomingEvent):
name = 'http-auth-received'
def get_instance(*args, **kwargs):
return HTTPAuth(*args, **kwargs), 'HTTPAuth'

View File

@ -50,8 +50,7 @@ class Message:
self.handlers = [('message', self._message_received)]
# XEPs for which this message module should not be executed
self._message_namespaces = set([nbxmpp.NS_HTTP_AUTH,
nbxmpp.NS_PUBSUB_EVENT,
self._message_namespaces = set([nbxmpp.NS_PUBSUB_EVENT,
nbxmpp.NS_ROSTERX,
nbxmpp.NS_MAM_1,
nbxmpp.NS_MAM_2,
@ -60,6 +59,10 @@ class Message:
nbxmpp.NS_CAPTCHA,])
def _message_received(self, _con, stanza, properties):
if properties.is_http_auth:
self._con.get_module('HTTPAuth').delegate(stanza, properties)
raise nbxmpp.NodeProcessed
# Check if a child of the message contains any
# namespaces that we handle in other modules.
# nbxmpp executes less common handlers last