use Network Event Dispatcher in connection_handler to handle HttpAuth events.
This commit is contained in:
parent
796213c9cb
commit
01d486ec60
|
@ -41,6 +41,7 @@ from calendar import timegm
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import common.xmpp
|
import common.xmpp
|
||||||
|
import common.caps_cache as capscache
|
||||||
|
|
||||||
from common import helpers
|
from common import helpers
|
||||||
from common import gajim
|
from common import gajim
|
||||||
|
@ -50,8 +51,10 @@ from common.pubsub import ConnectionPubSub
|
||||||
from common.pep import ConnectionPEP
|
from common.pep import ConnectionPEP
|
||||||
from common.protocol.caps import ConnectionCaps
|
from common.protocol.caps import ConnectionCaps
|
||||||
from common.protocol.bytestream import ConnectionSocks5Bytestream
|
from common.protocol.bytestream import ConnectionSocks5Bytestream
|
||||||
import common.caps_cache as capscache
|
from common import ged
|
||||||
|
from common import nec
|
||||||
from common.nec import NetworkEvent
|
from common.nec import NetworkEvent
|
||||||
|
from plugins import GajimPlugin
|
||||||
if gajim.HAVE_FARSIGHT:
|
if gajim.HAVE_FARSIGHT:
|
||||||
from common.jingle import ConnectionJingle
|
from common.jingle import ConnectionJingle
|
||||||
else:
|
else:
|
||||||
|
@ -1008,6 +1011,9 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
||||||
self.gmail_last_tid = None
|
self.gmail_last_tid = None
|
||||||
self.gmail_last_time = None
|
self.gmail_last_time = None
|
||||||
|
|
||||||
|
gajim.ged.register_event_handler('http-auth-received', ged.CORE,
|
||||||
|
self._nec_http_auth_received)
|
||||||
|
|
||||||
def build_http_auth_answer(self, iq_obj, answer):
|
def build_http_auth_answer(self, iq_obj, answer):
|
||||||
if not self.connection or self.connected < 2:
|
if not self.connection or self.connected < 2:
|
||||||
return
|
return
|
||||||
|
@ -1022,17 +1028,17 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
||||||
common.xmpp.protocol.ERR_NOT_AUTHORIZED)
|
common.xmpp.protocol.ERR_NOT_AUTHORIZED)
|
||||||
self.connection.send(err)
|
self.connection.send(err)
|
||||||
|
|
||||||
|
def _nec_http_auth_received(self, obj):
|
||||||
|
if obj.conn.name != self.name:
|
||||||
|
return
|
||||||
|
if obj.opt in ('yes', 'no'):
|
||||||
|
obj.conn.build_http_auth_answer(obj.iq_obj, obj.opt)
|
||||||
|
return True
|
||||||
|
|
||||||
def _HttpAuthCB(self, con, iq_obj):
|
def _HttpAuthCB(self, con, iq_obj):
|
||||||
log.debug('HttpAuthCB')
|
log.debug('HttpAuthCB')
|
||||||
opt = gajim.config.get_per('accounts', self.name, 'http_auth')
|
gajim.nec.push_incoming_event(HttpAuthReceivedEvent(None, conn=self,
|
||||||
if opt in ('yes', 'no'):
|
iq_obj=iq_obj))
|
||||||
self.build_http_auth_answer(iq_obj, opt)
|
|
||||||
else:
|
|
||||||
id_ = iq_obj.getTagAttr('confirm', 'id')
|
|
||||||
method = iq_obj.getTagAttr('confirm', 'method')
|
|
||||||
url = iq_obj.getTagAttr('confirm', 'url')
|
|
||||||
msg = iq_obj.getTagData('body') # In case it's a message with a body
|
|
||||||
self.dispatch('HTTP_AUTH', (method, url, id_, iq_obj, msg))
|
|
||||||
raise common.xmpp.NodeProcessed
|
raise common.xmpp.NodeProcessed
|
||||||
|
|
||||||
def _ErrorCB(self, con, iq_obj):
|
def _ErrorCB(self, con, iq_obj):
|
||||||
|
@ -2459,3 +2465,21 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
||||||
con.RegisterHandler('presence', self._StanzaArrivedCB)
|
con.RegisterHandler('presence', self._StanzaArrivedCB)
|
||||||
con.RegisterHandler('message', self._StanzaArrivedCB)
|
con.RegisterHandler('message', self._StanzaArrivedCB)
|
||||||
con.RegisterHandler('unknown', self._StreamCB, 'urn:ietf:params:xml:ns:xmpp-streams', xmlns='http://etherx.jabber.org/streams')
|
con.RegisterHandler('unknown', self._StreamCB, 'urn:ietf:params:xml:ns:xmpp-streams', xmlns='http://etherx.jabber.org/streams')
|
||||||
|
|
||||||
|
class HttpAuthReceivedEvent(nec.NetworkIncomingEvent):
|
||||||
|
name = 'http-auth-received'
|
||||||
|
base_network_events = []
|
||||||
|
|
||||||
|
def generate(self):
|
||||||
|
if not self.conn:
|
||||||
|
self.conn = self.base_event.conn
|
||||||
|
if not self.iq_obj:
|
||||||
|
self.iq_obj = self.base_event.xmpp_iq
|
||||||
|
|
||||||
|
self.opt = gajim.config.get_per('accounts', self.conn.name, 'http_auth')
|
||||||
|
self.iq_id = self.iq_obj.getTagAttr('confirm', 'id')
|
||||||
|
self.method = self.iq_obj.getTagAttr('confirm', 'method')
|
||||||
|
self.url = self.iq_obj.getTagAttr('confirm', 'url')
|
||||||
|
# In case it's a message with a body
|
||||||
|
self.msg = self.iq_obj.getTagData('body')
|
||||||
|
return True
|
||||||
|
|
|
@ -30,6 +30,9 @@ log = logging.getLogger('gajim.common.ged')
|
||||||
PRECORE = 30
|
PRECORE = 30
|
||||||
CORE = 40
|
CORE = 40
|
||||||
POSTCORE = 50
|
POSTCORE = 50
|
||||||
|
GUI1 = 60
|
||||||
|
GUI2 = 70
|
||||||
|
POSTGUI = 80
|
||||||
|
|
||||||
class GlobalEventsDispatcher(object):
|
class GlobalEventsDispatcher(object):
|
||||||
|
|
||||||
|
@ -61,4 +64,5 @@ class GlobalEventsDispatcher(object):
|
||||||
log.debug('%s\nArgs: %s'%(event_name, str(args)))
|
log.debug('%s\nArgs: %s'%(event_name, str(args)))
|
||||||
if event_name in self.handlers:
|
if event_name in self.handlers:
|
||||||
for priority, handler in self.handlers[event_name]:
|
for priority, handler in self.handlers[event_name]:
|
||||||
handler(*args, **kwargs)
|
if handler(*args, **kwargs):
|
||||||
|
return
|
||||||
|
|
|
@ -41,7 +41,9 @@ class NetworkEventsController(object):
|
||||||
|
|
||||||
def register_incoming_event(self, event_class):
|
def register_incoming_event(self, event_class):
|
||||||
for base_event_name in event_class.base_network_events:
|
for base_event_name in event_class.base_network_events:
|
||||||
self.incoming_events_generators.setdefault(base_event_name, []).append(event_class)
|
event_list = self.incoming_events_generators.setdefault(base_event_name, [])
|
||||||
|
if not event_class in event_list:
|
||||||
|
event_list.append(event_class)
|
||||||
|
|
||||||
def unregister_incoming_event(self, event_class):
|
def unregister_incoming_event(self, event_class):
|
||||||
for base_event_name in event_class.base_network_events:
|
for base_event_name in event_class.base_network_events:
|
||||||
|
@ -55,8 +57,9 @@ class NetworkEventsController(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def push_incoming_event(self, event_object):
|
def push_incoming_event(self, event_object):
|
||||||
if self._generate_events_based_on_incoming_event(event_object):
|
if event_object.generate():
|
||||||
gajim.ged.raise_event(event_object.name, event_object)
|
if self._generate_events_based_on_incoming_event(event_object):
|
||||||
|
gajim.ged.raise_event(event_object.name, event_object)
|
||||||
|
|
||||||
def push_outgoing_event(self, event_object):
|
def push_outgoing_event(self, event_object):
|
||||||
pass
|
pass
|
||||||
|
@ -93,25 +96,7 @@ class NetworkEvent(object):
|
||||||
def init(self):
|
def init(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _set_kwargs_as_attributes(self, **kwargs):
|
|
||||||
for k, v in kwargs.iteritems():
|
|
||||||
setattr(self, k, v)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return '<NetworkEvent object> Attributes: %s'%(pformat(self.__dict__))
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return '<NetworkEvent object> Attributes: %s'%(pformat(self.__dict__))
|
|
||||||
|
|
||||||
class NetworkIncomingEvent(NetworkEvent):
|
|
||||||
base_network_events = []
|
|
||||||
'''
|
|
||||||
Names of base network events that new event is going to be generated on.
|
|
||||||
'''
|
|
||||||
|
|
||||||
def init(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
'''
|
'''
|
||||||
Generates new event (sets it's attributes) based on event object.
|
Generates new event (sets it's attributes) based on event object.
|
||||||
|
@ -125,10 +110,25 @@ class NetworkIncomingEvent(NetworkEvent):
|
||||||
|
|
||||||
:return: True if generated event should be dispatched, False otherwise.
|
:return: True if generated event should be dispatched, False otherwise.
|
||||||
'''
|
'''
|
||||||
pass
|
return True
|
||||||
|
|
||||||
|
def _set_kwargs_as_attributes(self, **kwargs):
|
||||||
|
for k, v in kwargs.iteritems():
|
||||||
|
setattr(self, k, v)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '<NetworkEvent object> Attributes: %s'%(pformat(self.__dict__))
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<NetworkEvent object> Attributes: %s'%(pformat(self.__dict__))
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkIncomingEvent(NetworkEvent):
|
||||||
|
base_network_events = []
|
||||||
|
'''
|
||||||
|
Names of base network events that new event is going to be generated on.
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
class NetworkOutgoingEvent(NetworkEvent):
|
class NetworkOutgoingEvent(NetworkEvent):
|
||||||
|
pass
|
||||||
def init(self):
|
|
||||||
pass
|
|
|
@ -147,23 +147,24 @@ class Interface:
|
||||||
self.instances['change_nick_dialog'] = dialogs.ChangeNickDialog(
|
self.instances['change_nick_dialog'] = dialogs.ChangeNickDialog(
|
||||||
account, room_jid, title, prompt)
|
account, room_jid, title, prompt)
|
||||||
|
|
||||||
def handle_event_http_auth(self, account, data):
|
def handle_event_http_auth(self, obj):
|
||||||
#('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg))
|
#('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg))
|
||||||
def response(account, iq_obj, answer):
|
def response(account, answer):
|
||||||
gajim.connections[account].build_http_auth_answer(iq_obj, answer)
|
obj.conn.build_http_auth_answer(obj.iq_obj, answer)
|
||||||
|
|
||||||
def on_yes(is_checked, account, iq_obj):
|
def on_yes(is_checked, obj):
|
||||||
response(account, iq_obj, 'yes')
|
response(obj, 'yes')
|
||||||
|
|
||||||
|
account = obj.conn.name
|
||||||
sec_msg = _('Do you accept this request?')
|
sec_msg = _('Do you accept this request?')
|
||||||
if gajim.get_number_of_connected_accounts() > 1:
|
if gajim.get_number_of_connected_accounts() > 1:
|
||||||
sec_msg = _('Do you accept this request on account %s?') % account
|
sec_msg = _('Do you accept this request on account %s?') % account
|
||||||
if data[4]:
|
if obj.msg:
|
||||||
sec_msg = data[4] + '\n' + sec_msg
|
sec_msg = obj.msg + '\n' + sec_msg
|
||||||
dialog = dialogs.YesNoDialog(_('HTTP (%(method)s) Authorization for '
|
dialog = dialogs.YesNoDialog(_('HTTP (%(method)s) Authorization for '
|
||||||
'%(url)s (id: %(id)s)') % {'method': data[0], 'url': data[1],
|
'%(url)s (id: %(id)s)') % {'method': obj.method, 'url': obj.url,
|
||||||
'id': data[2]}, sec_msg, on_response_yes=(on_yes, account, data[3]),
|
'id': obj.iq_id}, sec_msg, on_response_yes=(on_yes, obj),
|
||||||
on_response_no=(response, account, data[3], 'no'))
|
on_response_no=(response, obj, 'no'))
|
||||||
|
|
||||||
def handle_event_error_answer(self, account, array):
|
def handle_event_error_answer(self, account, array):
|
||||||
#('ERROR_ANSWER', account, (id, jid_from, errmsg, errcode))
|
#('ERROR_ANSWER', account, (id, jid_from, errmsg, errcode))
|
||||||
|
@ -2140,7 +2141,6 @@ class Interface:
|
||||||
'FILE_SEND_ERROR': [self.handle_event_file_send_error],
|
'FILE_SEND_ERROR': [self.handle_event_file_send_error],
|
||||||
'STANZA_ARRIVED': [self.handle_event_stanza_arrived],
|
'STANZA_ARRIVED': [self.handle_event_stanza_arrived],
|
||||||
'STANZA_SENT': [self.handle_event_stanza_sent],
|
'STANZA_SENT': [self.handle_event_stanza_sent],
|
||||||
'HTTP_AUTH': [self.handle_event_http_auth],
|
|
||||||
'VCARD_PUBLISHED': [self.handle_event_vcard_published],
|
'VCARD_PUBLISHED': [self.handle_event_vcard_published],
|
||||||
'VCARD_NOT_PUBLISHED': [self.handle_event_vcard_not_published],
|
'VCARD_NOT_PUBLISHED': [self.handle_event_vcard_not_published],
|
||||||
'ASK_NEW_NICK': [self.handle_event_ask_new_nick],
|
'ASK_NEW_NICK': [self.handle_event_ask_new_nick],
|
||||||
|
@ -2181,7 +2181,8 @@ class Interface:
|
||||||
'JINGLE_DISCONNECTED': [self.handle_event_jingle_disconnected],
|
'JINGLE_DISCONNECTED': [self.handle_event_jingle_disconnected],
|
||||||
'JINGLE_ERROR': [self.handle_event_jingle_error],
|
'JINGLE_ERROR': [self.handle_event_jingle_error],
|
||||||
'PEP_RECEIVED': [self.handle_event_pep_received],
|
'PEP_RECEIVED': [self.handle_event_pep_received],
|
||||||
'CAPS_RECEIVED': [self.handle_event_caps_received]
|
'CAPS_RECEIVED': [self.handle_event_caps_received],
|
||||||
|
'http-auth-received': [self.handle_event_http_auth],
|
||||||
}
|
}
|
||||||
|
|
||||||
def register_core_handlers(self):
|
def register_core_handlers(self):
|
||||||
|
@ -2192,7 +2193,7 @@ class Interface:
|
||||||
"""
|
"""
|
||||||
for event_name, event_handlers in self.handlers.iteritems():
|
for event_name, event_handlers in self.handlers.iteritems():
|
||||||
for event_handler in event_handlers:
|
for event_handler in event_handlers:
|
||||||
gajim.ged.register_event_handler(event_name, ged.CORE,
|
gajim.ged.register_event_handler(event_name, ged.GUI1,
|
||||||
event_handler)
|
event_handler)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
Loading…
Reference in New Issue