Use nbxmpp properties for HTTPAuth
nbxmpp implements HTTPAuth now, so we dont need to parse it anymore
This commit is contained in:
parent
42c1909d3b
commit
85e79e7b27
|
@ -420,7 +420,11 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
|
||||||
app.nec.push_incoming_event(IqErrorReceivedEvent(None, conn=self,
|
app.nec.push_incoming_event(IqErrorReceivedEvent(None, conn=self,
|
||||||
stanza=iq_obj))
|
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()
|
id_ = iq_obj.getID()
|
||||||
|
|
||||||
app.nec.push_incoming_event(NetworkEvent('raw-iq-received',
|
app.nec.push_incoming_event(NetworkEvent('raw-iq-received',
|
||||||
|
|
|
@ -19,7 +19,7 @@ import logging
|
||||||
import nbxmpp
|
import nbxmpp
|
||||||
|
|
||||||
from gajim.common import app
|
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')
|
log = logging.getLogger('gajim.c.m.http_auth')
|
||||||
|
|
||||||
|
@ -29,12 +29,9 @@ class HTTPAuth:
|
||||||
self._con = con
|
self._con = con
|
||||||
self._account = con.name
|
self._account = con.name
|
||||||
|
|
||||||
self.handlers = [
|
self.handlers = []
|
||||||
('iq', self.answer_request, 'get', nbxmpp.NS_HTTP_AUTH),
|
|
||||||
('message', self.answer_request, '', nbxmpp.NS_HTTP_AUTH)
|
|
||||||
]
|
|
||||||
|
|
||||||
def answer_request(self, _con, stanza):
|
def delegate(self, stanza, properties):
|
||||||
log.info('Auth request received')
|
log.info('Auth request received')
|
||||||
auto_answer = app.config.get_per(
|
auto_answer = app.config.get_per(
|
||||||
'accounts', self._account, 'http_auth')
|
'accounts', self._account, 'http_auth')
|
||||||
|
@ -42,21 +39,14 @@ class HTTPAuth:
|
||||||
self.build_http_auth_answer(stanza, auto_answer)
|
self.build_http_auth_answer(stanza, auto_answer)
|
||||||
raise nbxmpp.NodeProcessed
|
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(
|
app.nec.push_incoming_event(
|
||||||
HttpAuthReceivedEvent(None, conn=self._con,
|
NetworkEvent('http-auth-received',
|
||||||
iq_id=iq_id,
|
conn=self._con,
|
||||||
method=method,
|
iq_id=properties['id'],
|
||||||
url=url,
|
method=properties['method'],
|
||||||
msg=msg,
|
url=properties['url'],
|
||||||
stanza=stanza))
|
msg=properties['body'],
|
||||||
|
stanza=stanza))
|
||||||
raise nbxmpp.NodeProcessed
|
|
||||||
|
|
||||||
def build_http_auth_answer(self, stanza, answer):
|
def build_http_auth_answer(self, stanza, answer):
|
||||||
if answer == 'yes':
|
if answer == 'yes':
|
||||||
|
@ -72,9 +62,5 @@ class HTTPAuth:
|
||||||
self._con.connection.send(err)
|
self._con.connection.send(err)
|
||||||
|
|
||||||
|
|
||||||
class HttpAuthReceivedEvent(NetworkIncomingEvent):
|
|
||||||
name = 'http-auth-received'
|
|
||||||
|
|
||||||
|
|
||||||
def get_instance(*args, **kwargs):
|
def get_instance(*args, **kwargs):
|
||||||
return HTTPAuth(*args, **kwargs), 'HTTPAuth'
|
return HTTPAuth(*args, **kwargs), 'HTTPAuth'
|
||||||
|
|
|
@ -50,8 +50,7 @@ class Message:
|
||||||
self.handlers = [('message', self._message_received)]
|
self.handlers = [('message', self._message_received)]
|
||||||
|
|
||||||
# XEPs for which this message module should not be executed
|
# XEPs for which this message module should not be executed
|
||||||
self._message_namespaces = set([nbxmpp.NS_HTTP_AUTH,
|
self._message_namespaces = set([nbxmpp.NS_PUBSUB_EVENT,
|
||||||
nbxmpp.NS_PUBSUB_EVENT,
|
|
||||||
nbxmpp.NS_ROSTERX,
|
nbxmpp.NS_ROSTERX,
|
||||||
nbxmpp.NS_MAM_1,
|
nbxmpp.NS_MAM_1,
|
||||||
nbxmpp.NS_MAM_2,
|
nbxmpp.NS_MAM_2,
|
||||||
|
@ -60,6 +59,10 @@ class Message:
|
||||||
nbxmpp.NS_CAPTCHA,])
|
nbxmpp.NS_CAPTCHA,])
|
||||||
|
|
||||||
def _message_received(self, _con, stanza, properties):
|
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
|
# Check if a child of the message contains any
|
||||||
# namespaces that we handle in other modules.
|
# namespaces that we handle in other modules.
|
||||||
# nbxmpp executes less common handlers last
|
# nbxmpp executes less common handlers last
|
||||||
|
|
Loading…
Reference in New Issue