Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
85e79e7b
by Philipp Hörist at 2018-12-21T11:23:26Z
3 changed files:
- gajim/common/connection_handlers.py
- gajim/common/modules/http_auth.py
- gajim/common/modules/message.py
Changes:
| ... | ... | @@ -420,7 +420,11 @@ class ConnectionHandlers(ConnectionSocks5Bytestream, |
| 420 | 420 |
app.nec.push_incoming_event(IqErrorReceivedEvent(None, conn=self,
|
| 421 | 421 |
stanza=iq_obj))
|
| 422 | 422 |
|
| 423 |
- def _IqCB(self, con, iq_obj):
|
|
| 423 |
+ def _IqCB(self, con, iq_obj, properties):
|
|
| 424 |
+ if properties.is_http_auth:
|
|
| 425 |
+ self.get_module('HTTPAuth').delegate(iq_obj, properties)
|
|
| 426 |
+ raise nbxmpp.NodeProcessed
|
|
| 427 |
+ |
|
| 424 | 428 |
id_ = iq_obj.getID()
|
| 425 | 429 |
|
| 426 | 430 |
app.nec.push_incoming_event(NetworkEvent('raw-iq-received',
|
| ... | ... | @@ -19,7 +19,7 @@ import logging |
| 19 | 19 |
import nbxmpp
|
| 20 | 20 |
|
| 21 | 21 |
from gajim.common import app
|
| 22 |
-from gajim.common.nec import NetworkIncomingEvent
|
|
| 22 |
+from gajim.common.nec import NetworkEvent
|
|
| 23 | 23 |
|
| 24 | 24 |
log = logging.getLogger('gajim.c.m.http_auth')
|
| 25 | 25 |
|
| ... | ... | @@ -29,12 +29,9 @@ class HTTPAuth: |
| 29 | 29 |
self._con = con
|
| 30 | 30 |
self._account = con.name
|
| 31 | 31 |
|
| 32 |
- self.handlers = [
|
|
| 33 |
- ('iq', self.answer_request, 'get', nbxmpp.NS_HTTP_AUTH),
|
|
| 34 |
- ('message', self.answer_request, '', nbxmpp.NS_HTTP_AUTH)
|
|
| 35 |
- ]
|
|
| 32 |
+ self.handlers = []
|
|
| 36 | 33 |
|
| 37 |
- def answer_request(self, _con, stanza):
|
|
| 34 |
+ def delegate(self, stanza, properties):
|
|
| 38 | 35 |
log.info('Auth request received')
|
| 39 | 36 |
auto_answer = app.config.get_per(
|
| 40 | 37 |
'accounts', self._account, 'http_auth')
|
| ... | ... | @@ -42,21 +39,14 @@ class HTTPAuth: |
| 42 | 39 |
self.build_http_auth_answer(stanza, auto_answer)
|
| 43 | 40 |
raise nbxmpp.NodeProcessed
|
| 44 | 41 |
|
| 45 |
- iq_id = stanza.getTagAttr('confirm', 'id')
|
|
| 46 |
- method = stanza.getTagAttr('confirm', 'method')
|
|
| 47 |
- url = stanza.getTagAttr('confirm', 'url')
|
|
| 48 |
- # In case it's a message with a body
|
|
| 49 |
- msg = stanza.getTagData('body')
|
|
| 50 |
- |
|
| 51 | 42 |
app.nec.push_incoming_event(
|
| 52 |
- HttpAuthReceivedEvent(None, conn=self._con,
|
|
| 53 |
- iq_id=iq_id,
|
|
| 54 |
- method=method,
|
|
| 55 |
- url=url,
|
|
| 56 |
- msg=msg,
|
|
| 57 |
- stanza=stanza))
|
|
| 58 |
- |
|
| 59 |
- raise nbxmpp.NodeProcessed
|
|
| 43 |
+ NetworkEvent('http-auth-received',
|
|
| 44 |
+ conn=self._con,
|
|
| 45 |
+ iq_id=properties['id'],
|
|
| 46 |
+ method=properties['method'],
|
|
| 47 |
+ url=properties['url'],
|
|
| 48 |
+ msg=properties['body'],
|
|
| 49 |
+ stanza=stanza))
|
|
| 60 | 50 |
|
| 61 | 51 |
def build_http_auth_answer(self, stanza, answer):
|
| 62 | 52 |
if answer == 'yes':
|
| ... | ... | @@ -72,9 +62,5 @@ class HTTPAuth: |
| 72 | 62 |
self._con.connection.send(err)
|
| 73 | 63 |
|
| 74 | 64 |
|
| 75 |
-class HttpAuthReceivedEvent(NetworkIncomingEvent):
|
|
| 76 |
- name = 'http-auth-received'
|
|
| 77 |
- |
|
| 78 |
- |
|
| 79 | 65 |
def get_instance(*args, **kwargs):
|
| 80 | 66 |
return HTTPAuth(*args, **kwargs), 'HTTPAuth'
|
| ... | ... | @@ -50,8 +50,7 @@ class Message: |
| 50 | 50 |
self.handlers = [('message', self._message_received)]
|
| 51 | 51 |
|
| 52 | 52 |
# XEPs for which this message module should not be executed
|
| 53 |
- self._message_namespaces = set([nbxmpp.NS_HTTP_AUTH,
|
|
| 54 |
- nbxmpp.NS_PUBSUB_EVENT,
|
|
| 53 |
+ self._message_namespaces = set([nbxmpp.NS_PUBSUB_EVENT,
|
|
| 55 | 54 |
nbxmpp.NS_ROSTERX,
|
| 56 | 55 |
nbxmpp.NS_MAM_1,
|
| 57 | 56 |
nbxmpp.NS_MAM_2,
|
| ... | ... | @@ -60,6 +59,10 @@ class Message: |
| 60 | 59 |
nbxmpp.NS_CAPTCHA,])
|
| 61 | 60 |
|
| 62 | 61 |
def _message_received(self, _con, stanza, properties):
|
| 62 |
+ if properties.is_http_auth:
|
|
| 63 |
+ self._con.get_module('HTTPAuth').delegate(stanza, properties)
|
|
| 64 |
+ raise nbxmpp.NodeProcessed
|
|
| 65 |
+ |
|
| 63 | 66 |
# Check if a child of the message contains any
|
| 64 | 67 |
# namespaces that we handle in other modules.
|
| 65 | 68 |
# nbxmpp executes less common handlers last
|