diff --git a/src/common/connection.py b/src/common/connection.py index 0de9dfb07..257bc3465 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -590,6 +590,12 @@ class Connection: jid_from = str(iq_obj.getFrom()) self.dispatch('ERROR_ANSWER', (jid_from, errmsg, errcode)) + def _event_dispatcher(self, realm, event, data): + if realm == common.xmpp.NS_REGISTER: + if event == common.xmpp.features.REGISTER_DATA_RECEIVED: + # data is (agent, DataFrom) + self.dispatch('REGISTER_AGENT_INFO', (data[0], data[1].asDict())) + def connect(self): """Connect and authenticate to the Jabber server""" name = gajim.config.get_per('accounts', self.name, 'name') @@ -659,6 +665,7 @@ class Connection: con.RegisterHandler('iq', self._PrivateCB, 'result', common.xmpp.NS_PRIVATE) con.RegisterHandler('iq', self._ErrorCB, 'error') + con.RegisterEventHandler(self._event_dispatcher) gajim.log.debug('Connected to server') @@ -846,34 +853,10 @@ class Connection: queryNS = common.xmpp.NS_BROWSE)) self.discoverInfo(jid, node) - def _receive_register_agent_info(self, con, iq_obj, agent): - if not common.xmpp.isResultNode(iq_obj): - return - iq = common.xmpp.Iq('get', common.xmpp.NS_REGISTER, to = agent) - df = iq_obj.getTag('query', namespace = common.xmpp.NS_REGISTER).\ - getTag('x', namespace = common.xmpp.NS_DATA) - if df: - df = common.xmpp.DataForm(node = df) - self.dispatch('REGISTER_AGENT_INFO', (agent, df.asDict())) - return - df = common.xmpp.DataForm(typ = 'form') - for i in iq_obj.getQueryPayload(): - if type(i) != type(iq): - pass - elif i.getName() == 'instructions': - df.addInstructions(i.getData()) - else: - df.setField(i.getName()).setValue(i.getData()) - self.dispatch('REGISTER_AGENT_INFO', (agent, df.asDict())) - return - def request_register_agent_info(self, agent): if not self.connection: return None - iq = common.xmpp.Iq('get', common.xmpp.NS_REGISTER, to = agent) - self.connection.SendAndCallForResponse(iq, - self._receive_register_agent_info, {'agent': agent}) - return + common.xmpp.features.getRegInfo(self.connection, agent) def register_agent(self, agent, info): if not self.connection: diff --git a/src/common/xmpp/features.py b/src/common/xmpp/features.py index 9660077db..54d8cb53b 100644 --- a/src/common/xmpp/features.py +++ b/src/common/xmpp/features.py @@ -26,6 +26,8 @@ All these methods takes 'disp' first argument that should be already connected from protocol import * +REGISTER_DATA_RECEIVED='REGISTER DATA RECEIVED' + ### DISCO ### http://jabber.org/protocol/disco ### JEP-0030 #################### ### Browse ### jabber:iq:browse ### JEP-0030 ################################### ### Agents ### jabber:iq:agents ### JEP-0030 ################################### @@ -82,16 +84,21 @@ def getRegInfo(disp,host,info={}): 'disp' must be connected dispatcher instance.""" iq=Iq('get',NS_REGISTER,to=host) for i in info.keys(): iq.setTagData(i,info[i]) - resp=disp.SendAndWaitForResponse(iq) + disp.SendAndCallForResponse(iq,_ReceivedRegInfo, {'agent': host}) + +def _ReceivedRegInfo(con, resp, agent): + iq=Iq('get',NS_REGISTER,to=agent) if not isResultNode(resp): return df=resp.getTag('query',namespace=NS_REGISTER).getTag('x',namespace=NS_DATA) - if df: return DataForm(node=df) + if df: + con.Event(NS_REGISTER,REGISTER_DATA_RECEIVED,(agent, DataForm(node=df))) + return df=DataForm(typ='form') for i in resp.getQueryPayload(): if type(i)<>type(iq): pass elif i.getName()=='instructions': df.addInstructions(i.getData()) else: df.setField(i.getName()).setValue(i.getData()) - return df + con.Event(NS_REGISTER,REGISTER_DATA_RECEIVED,(agent, df)) def register(disp,host,info): """ Perform registration on remote server with provided info.