request_register_agent_info is now asynch in xmpp
This commit is contained in:
parent
c6a53d8732
commit
8b6bb3ef0c
|
@ -590,6 +590,12 @@ class Connection:
|
||||||
jid_from = str(iq_obj.getFrom())
|
jid_from = str(iq_obj.getFrom())
|
||||||
self.dispatch('ERROR_ANSWER', (jid_from, errmsg, errcode))
|
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):
|
def connect(self):
|
||||||
"""Connect and authenticate to the Jabber server"""
|
"""Connect and authenticate to the Jabber server"""
|
||||||
name = gajim.config.get_per('accounts', self.name, 'name')
|
name = gajim.config.get_per('accounts', self.name, 'name')
|
||||||
|
@ -659,6 +665,7 @@ class Connection:
|
||||||
con.RegisterHandler('iq', self._PrivateCB, 'result',
|
con.RegisterHandler('iq', self._PrivateCB, 'result',
|
||||||
common.xmpp.NS_PRIVATE)
|
common.xmpp.NS_PRIVATE)
|
||||||
con.RegisterHandler('iq', self._ErrorCB, 'error')
|
con.RegisterHandler('iq', self._ErrorCB, 'error')
|
||||||
|
con.RegisterEventHandler(self._event_dispatcher)
|
||||||
|
|
||||||
gajim.log.debug('Connected to server')
|
gajim.log.debug('Connected to server')
|
||||||
|
|
||||||
|
@ -846,34 +853,10 @@ class Connection:
|
||||||
queryNS = common.xmpp.NS_BROWSE))
|
queryNS = common.xmpp.NS_BROWSE))
|
||||||
self.discoverInfo(jid, node)
|
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):
|
def request_register_agent_info(self, agent):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return None
|
return None
|
||||||
iq = common.xmpp.Iq('get', common.xmpp.NS_REGISTER, to = agent)
|
common.xmpp.features.getRegInfo(self.connection, agent)
|
||||||
self.connection.SendAndCallForResponse(iq,
|
|
||||||
self._receive_register_agent_info, {'agent': agent})
|
|
||||||
return
|
|
||||||
|
|
||||||
def register_agent(self, agent, info):
|
def register_agent(self, agent, info):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
|
|
|
@ -26,6 +26,8 @@ All these methods takes 'disp' first argument that should be already connected
|
||||||
|
|
||||||
from protocol import *
|
from protocol import *
|
||||||
|
|
||||||
|
REGISTER_DATA_RECEIVED='REGISTER DATA RECEIVED'
|
||||||
|
|
||||||
### DISCO ### http://jabber.org/protocol/disco ### JEP-0030 ####################
|
### DISCO ### http://jabber.org/protocol/disco ### JEP-0030 ####################
|
||||||
### Browse ### jabber:iq:browse ### JEP-0030 ###################################
|
### Browse ### jabber:iq:browse ### JEP-0030 ###################################
|
||||||
### Agents ### jabber:iq:agents ### JEP-0030 ###################################
|
### Agents ### jabber:iq:agents ### JEP-0030 ###################################
|
||||||
|
@ -82,16 +84,21 @@ def getRegInfo(disp,host,info={}):
|
||||||
'disp' must be connected dispatcher instance."""
|
'disp' must be connected dispatcher instance."""
|
||||||
iq=Iq('get',NS_REGISTER,to=host)
|
iq=Iq('get',NS_REGISTER,to=host)
|
||||||
for i in info.keys(): iq.setTagData(i,info[i])
|
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
|
if not isResultNode(resp): return
|
||||||
df=resp.getTag('query',namespace=NS_REGISTER).getTag('x',namespace=NS_DATA)
|
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')
|
df=DataForm(typ='form')
|
||||||
for i in resp.getQueryPayload():
|
for i in resp.getQueryPayload():
|
||||||
if type(i)<>type(iq): pass
|
if type(i)<>type(iq): pass
|
||||||
elif i.getName()=='instructions': df.addInstructions(i.getData())
|
elif i.getName()=='instructions': df.addInstructions(i.getData())
|
||||||
else: df.setField(i.getName()).setValue(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):
|
def register(disp,host,info):
|
||||||
""" Perform registration on remote server with provided info.
|
""" Perform registration on remote server with provided info.
|
||||||
|
|
Loading…
Reference in New Issue