Hi all, I started to look seriously a plugin system branch, and use it to dispatch events. I did a proof of concept patch. First I explain how things used to work before:
XML stream -> xmpppy (parse XML) -> connection.py -> dispatch event to GUI with all arguments The way it works now: XML stream -> xmpppy (parse XML) -> connection.py -> NEC (create an HttpAuthReceivedEvent object, which extract data from stanza) -> GED (dispatch it to handlers) In case of HTTP_AUTH (the patch attached) a first handler is in connection_handlers.py, and, if the option is set for that, sends answer automatically and stop propagation a second handler is in gui_interface.py and is called if first one didn't stopped propagation, and shows a dialog to the user. This is only a proof of concept and has to be used for all events. But we need to decide what's the best with this branch. I see 2 options: - we merge it to trunk, and start to develop in it. That should not break anything why we slowly merge to this new event flow - release 0.14 as soon as possible, and merge it to trunk for 0.15 only. Comments are more than welcome! -- Yann
diff -r 96aff3fee71f src/common/connection_handlers.py --- a/src/common/connection_handlers.py Fri Feb 12 21:08:40 2010 +0100 +++ b/src/common/connection_handlers.py Thu Feb 18 21:58:27 2010 +0100 @@ -41,6 +41,7 @@ import datetime import common.xmpp +import common.caps_cache as capscache from common import helpers from common import gajim @@ -50,8 +51,10 @@ from common.pep import ConnectionPEP from common.protocol.caps import ConnectionCaps from common.protocol.bytestream import ConnectionBytestream -import common.caps_cache as capscache +from common import ged +from common import nec from common.nec import NetworkEvent +from plugins import GajimPlugin if gajim.HAVE_FARSIGHT: from common.jingle import ConnectionJingle else: @@ -547,8 +550,8 @@ id_ = iq_obj.getID() gajim.nec.push_incoming_event(NetworkEvent('raw-iq-received', - conn = con, - xmpp_iq = iq_obj)) + conn = con, + xmpp_iq = iq_obj)) # Check if we were waiting a timeout for this id found_tim = None @@ -956,6 +959,10 @@ self.gmail_last_tid = None self.gmail_last_time = None + gajim.nec.register_incoming_event(HttpAuthReceivedEvent) + gajim.ged.register_event_handler('http-auth-received', ged.CORE, + self._nec_http_auth_received) + def build_http_auth_answer(self, iq_obj, answer): if not self.connection or self.connected < 2: return @@ -966,17 +973,19 @@ common.xmpp.protocol.ERR_NOT_AUTHORIZED) 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): log.debug('HttpAuthCB') - opt = gajim.config.get_per('accounts', self.name, 'http_auth') - if opt in ('yes', 'no'): - 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)) + + gajim.nec.push_incoming_event(NetworkEvent('raw-http-auth-received', + conn=self, xmpp_iq=iq_obj)) + raise common.xmpp.NodeProcessed def _ErrorCB(self, con, iq_obj): @@ -1373,12 +1382,12 @@ log.debug('MessageCB') gajim.nec.push_incoming_event(NetworkEvent('raw-message-received', - conn = con, - xmpp_msg = msg, - account = self.name)) + conn = con, + xmpp_msg = msg, + account = self.name)) - mtype = msg.getType() - + mtype = msg.getType() + # check if the message is a roster item exchange (XEP-0144) if msg.getTag('x', namespace=common.xmpp.NS_ROSTERX): @@ -2313,4 +2322,20 @@ con.RegisterHandler('message', self._StanzaArrivedCB) 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 = ['raw-http-auth-received'] + + def generate(self): + self.conn = self.base_event.conn + 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 + # vim: se ts=3: diff -r 96aff3fee71f src/common/ged.py --- a/src/common/ged.py Fri Feb 12 21:08:40 2010 +0100 +++ b/src/common/ged.py Thu Feb 18 21:58:27 2010 +0100 @@ -30,6 +30,8 @@ PRECORE = 30 CORE = 40 POSTCORE = 50 +GUI = 60 +POSTGUI = 70 class GlobalEventsDispatcher(object): @@ -61,5 +63,6 @@ log.debug('%s\nArgs: %s'%(event_name, str(args))) if event_name in self.handlers: for priority, handler in self.handlers[event_name]: - handler(*args, **kwargs) - \ No newline at end of file + if handler(*args, **kwargs): + return + diff -r 96aff3fee71f src/common/nec.py --- a/src/common/nec.py Fri Feb 12 21:08:40 2010 +0100 +++ b/src/common/nec.py Thu Feb 18 21:58:27 2010 +0100 @@ -41,8 +41,11 @@ def register_incoming_event(self, event_class): 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): for base_event_name in event_class.base_network_events: if base_event_name in self.incoming_events_generators: @@ -132,4 +135,4 @@ def init(self): pass - \ No newline at end of file + diff -r 96aff3fee71f src/gui_interface.py --- a/src/gui_interface.py Fri Feb 12 21:08:40 2010 +0100 +++ b/src/gui_interface.py Thu Feb 18 21:58:27 2010 +0100 @@ -139,24 +139,25 @@ self.instances['change_nick_dialog'] = dialogs.ChangeNickDialog( 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)) - def response(account, iq_obj, answer): + def response(obj, answer): self.dialog.destroy() - gajim.connections[account].build_http_auth_answer(iq_obj, answer) - - def on_yes(is_checked, account, iq_obj): - response(account, iq_obj, 'yes') - + obj.conn.build_http_auth_answer(obj.iq_obj, answer) + + def on_yes(is_checked, obj): + response(obj, 'yes') + + account = obj.conn.name sec_msg = _('Do you accept this request?') if gajim.get_number_of_connected_accounts() > 1: sec_msg = _('Do you accept this request on account %s?') % account - if data[4]: - sec_msg = data[4] + '\n' + sec_msg + if obj.msg: + sec_msg = obj.msg + '\n' + sec_msg self.dialog = dialogs.YesNoDialog(_('HTTP (%(method)s) Authorization for ' - '%(url)s (id: %(id)s)') % {'method': data[0], 'url': data[1], - 'id': data[2]}, sec_msg, on_response_yes=(on_yes, account, data[3]), - on_response_no=(response, account, data[3], 'no')) + '%(url)s (id: %(id)s)') % {'method': obj.method, 'url': obj.url, + 'id': obj.iq_id}, sec_msg, on_response_yes=(on_yes, obj), + on_response_no=(response, obj, 'no')) def handle_event_error_answer(self, account, array): #('ERROR_ANSWER', account, (id, jid_from, errmsg, errcode)) @@ -2014,7 +2015,6 @@ 'FILE_SEND_ERROR': [self.handle_event_file_send_error], 'STANZA_ARRIVED': [self.handle_event_stanza_arrived], 'STANZA_SENT': [self.handle_event_stanza_sent], - 'HTTP_AUTH': [self.handle_event_http_auth], 'VCARD_PUBLISHED': [self.handle_event_vcard_published], 'VCARD_NOT_PUBLISHED': [self.handle_event_vcard_not_published], 'ASK_NEW_NICK': [self.handle_event_ask_new_nick], @@ -2053,7 +2053,8 @@ 'JINGLE_DISCONNECTED': [self.handle_event_jingle_disconnected], 'JINGLE_ERROR': [self.handle_event_jingle_error], '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): @@ -2064,7 +2065,7 @@ """ for event_name, event_handlers in self.handlers.iteritems(): for event_handler in event_handlers: - gajim.ged.register_event_handler(event_name, ged.CORE, + gajim.ged.register_event_handler(event_name, ged.GUI, event_handler) ################################################################################
_______________________________________________ Gajim-devel mailing list Gajim-devel@gajim.org http://lists.gajim.org/cgi-bin/listinfo/gajim-devel