HTTPAuth: Use nbxmpp handlers
This commit is contained in:
parent
d121bbf4ab
commit
d93fe8b1ea
|
@ -297,10 +297,6 @@ class ConnectionHandlers(ConnectionSocks5Bytestream,
|
||||||
stanza=iq_obj))
|
stanza=iq_obj))
|
||||||
|
|
||||||
def _IqCB(self, con, iq_obj, properties):
|
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',
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import nbxmpp
|
import nbxmpp
|
||||||
|
from nbxmpp.structs import StanzaHandler
|
||||||
|
from nbxmpp.protocol import NS_HTTP_AUTH
|
||||||
|
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common.nec import NetworkEvent
|
from gajim.common.nec import NetworkEvent
|
||||||
|
@ -29,9 +31,22 @@ class HTTPAuth:
|
||||||
self._con = con
|
self._con = con
|
||||||
self._account = con.name
|
self._account = con.name
|
||||||
|
|
||||||
self.handlers = []
|
self.handlers = [
|
||||||
|
StanzaHandler(name='message',
|
||||||
|
callback=self._http_auth,
|
||||||
|
ns=NS_HTTP_AUTH,
|
||||||
|
priority=45),
|
||||||
|
StanzaHandler(name='iq',
|
||||||
|
callback=self._http_auth,
|
||||||
|
typ='get',
|
||||||
|
ns=NS_HTTP_AUTH,
|
||||||
|
priority=45)
|
||||||
|
]
|
||||||
|
|
||||||
|
def _http_auth(self, _con, stanza, properties):
|
||||||
|
if not properties.is_http_auth:
|
||||||
|
return
|
||||||
|
|
||||||
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,11 +57,12 @@ class HTTPAuth:
|
||||||
app.nec.push_incoming_event(
|
app.nec.push_incoming_event(
|
||||||
NetworkEvent('http-auth-received',
|
NetworkEvent('http-auth-received',
|
||||||
conn=self._con,
|
conn=self._con,
|
||||||
iq_id=properties['id'],
|
iq_id=properties.http_auth.id,
|
||||||
method=properties['method'],
|
method=properties.http_auth.method,
|
||||||
url=properties['url'],
|
url=properties.http_auth.url,
|
||||||
msg=properties['body'],
|
msg=properties.http_auth.body,
|
||||||
stanza=stanza))
|
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':
|
||||||
|
|
|
@ -58,10 +58,6 @@ 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