Philipp Hörist pushed to branch master at gajim / gajim
Commits: 85e79e7b by Philipp Hörist at 2018-12-21T11:23:26Z Use nbxmpp properties for HTTPAuth
nbxmpp implements HTTPAuth now, so we dont need to parse it anymore
- - - - -
3 changed files:
- gajim/common/connection_handlers.py - gajim/common/modules/http_auth.py - gajim/common/modules/message.py
Changes:
===================================== gajim/common/connection_handlers.py ===================================== @@ -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',
===================================== gajim/common/modules/http_auth.py ===================================== @@ -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,21 +39,14 @@ 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, - stanza=stanza)) - - raise nbxmpp.NodeProcessed + NetworkEvent('http-auth-received', + conn=self._con, + iq_id=properties['id'], + method=properties['method'], + url=properties['url'], + msg=properties['body'], + stanza=stanza))
def build_http_auth_answer(self, stanza, answer): if answer == 'yes': @@ -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'
===================================== gajim/common/modules/message.py ===================================== @@ -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
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/85e79e7b279843d945230714f881f2fad45...