ability to send jabber:iq:last query over zeroconf. Fixes #5644
This commit is contained in:
parent
f0dde42f77
commit
28e2874853
|
@ -509,11 +509,25 @@ class CommonConnection:
|
||||||
def account_changed(self, new_name):
|
def account_changed(self, new_name):
|
||||||
self.name = new_name
|
self.name = new_name
|
||||||
|
|
||||||
def request_last_status_time(self, jid, resource):
|
def request_last_status_time(self, jid, resource, groupchat_jid=None):
|
||||||
"""
|
"""
|
||||||
To be implemented by derivated classes
|
groupchat_jid is used when we want to send a request to a real jid and
|
||||||
|
act as if the answer comes from the groupchat_jid
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
print 'request_last_status_time', self.connection
|
||||||
|
if not self.connection:
|
||||||
|
return
|
||||||
|
to_whom_jid = jid
|
||||||
|
if resource:
|
||||||
|
to_whom_jid += '/' + resource
|
||||||
|
iq = common.xmpp.Iq(to=to_whom_jid, typ='get', queryNS=\
|
||||||
|
common.xmpp.NS_LAST)
|
||||||
|
id_ = self.connection.getAnID()
|
||||||
|
iq.setID(id_)
|
||||||
|
if groupchat_jid:
|
||||||
|
self.groupchat_jids[id_] = groupchat_jid
|
||||||
|
self.last_ids.append(id_)
|
||||||
|
self.connection.send(iq)
|
||||||
|
|
||||||
def request_os_info(self, jid, resource):
|
def request_os_info(self, jid, resource):
|
||||||
"""
|
"""
|
||||||
|
@ -1756,25 +1770,6 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
self.connection = con
|
self.connection = con
|
||||||
common.xmpp.features_nb.getRegInfo(con, self._hostname)
|
common.xmpp.features_nb.getRegInfo(con, self._hostname)
|
||||||
|
|
||||||
def request_last_status_time(self, jid, resource, groupchat_jid=None):
|
|
||||||
"""
|
|
||||||
groupchat_jid is used when we want to send a request to a real jid and
|
|
||||||
act as if the answer comes from the groupchat_jid
|
|
||||||
"""
|
|
||||||
if not self.connection:
|
|
||||||
return
|
|
||||||
to_whom_jid = jid
|
|
||||||
if resource:
|
|
||||||
to_whom_jid += '/' + resource
|
|
||||||
iq = common.xmpp.Iq(to = to_whom_jid, typ = 'get', queryNS =\
|
|
||||||
common.xmpp.NS_LAST)
|
|
||||||
id_ = self.connection.getAnID()
|
|
||||||
iq.setID(id_)
|
|
||||||
if groupchat_jid:
|
|
||||||
self.groupchat_jids[id_] = groupchat_jid
|
|
||||||
self.last_ids.append(id_)
|
|
||||||
self.connection.send(iq)
|
|
||||||
|
|
||||||
def request_os_info(self, jid, resource, groupchat_jid=None):
|
def request_os_info(self, jid, resource, groupchat_jid=None):
|
||||||
"""
|
"""
|
||||||
groupchat_jid is used when we want to send a request to a real jid and
|
groupchat_jid is used when we want to send a request to a real jid and
|
||||||
|
|
|
@ -782,10 +782,42 @@ class ConnectionHandlersBase:
|
||||||
# keep the jids we auto added (transports contacts) to not send the
|
# keep the jids we auto added (transports contacts) to not send the
|
||||||
# SUBSCRIBED event to gui
|
# SUBSCRIBED event to gui
|
||||||
self.automatically_added = []
|
self.automatically_added = []
|
||||||
|
# IDs of jabber:iq:last requests
|
||||||
|
self.last_ids = []
|
||||||
|
|
||||||
# keep track of sessions this connection has with other JIDs
|
# keep track of sessions this connection has with other JIDs
|
||||||
self.sessions = {}
|
self.sessions = {}
|
||||||
|
|
||||||
|
def _ErrorCB(self, con, iq_obj):
|
||||||
|
log.debug('ErrorCB')
|
||||||
|
jid_from = helpers.get_full_jid_from_iq(iq_obj)
|
||||||
|
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(jid_from)
|
||||||
|
id_ = unicode(iq_obj.getID())
|
||||||
|
if id_ in self.last_ids:
|
||||||
|
self.dispatch('LAST_STATUS_TIME', (jid_stripped, resource, -1, ''))
|
||||||
|
self.last_ids.remove(id_)
|
||||||
|
return
|
||||||
|
|
||||||
|
def _LastResultCB(self, con, iq_obj):
|
||||||
|
log.debug('LastResultCB')
|
||||||
|
qp = iq_obj.getTag('query')
|
||||||
|
seconds = qp.getAttr('seconds')
|
||||||
|
status = qp.getData()
|
||||||
|
try:
|
||||||
|
seconds = int(seconds)
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
id_ = iq_obj.getID()
|
||||||
|
if id_ in self.groupchat_jids:
|
||||||
|
who = self.groupchat_jids[id_]
|
||||||
|
del self.groupchat_jids[id_]
|
||||||
|
else:
|
||||||
|
who = helpers.get_full_jid_from_iq(iq_obj)
|
||||||
|
if id_ in self.last_ids:
|
||||||
|
self.last_ids.remove(id_)
|
||||||
|
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who)
|
||||||
|
self.dispatch('LAST_STATUS_TIME', (jid_stripped, resource, seconds, status))
|
||||||
|
|
||||||
def get_sessions(self, jid):
|
def get_sessions(self, jid):
|
||||||
"""
|
"""
|
||||||
Get all sessions for the given full jid
|
Get all sessions for the given full jid
|
||||||
|
@ -936,8 +968,6 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
||||||
# keep the latest subscribed event for each jid to prevent loop when we
|
# keep the latest subscribed event for each jid to prevent loop when we
|
||||||
# acknowledge presences
|
# acknowledge presences
|
||||||
self.subscribed_events = {}
|
self.subscribed_events = {}
|
||||||
# IDs of jabber:iq:last requests
|
|
||||||
self.last_ids = []
|
|
||||||
# IDs of jabber:iq:version requests
|
# IDs of jabber:iq:version requests
|
||||||
self.version_ids = []
|
self.version_ids = []
|
||||||
# IDs of urn:xmpp:time requests
|
# IDs of urn:xmpp:time requests
|
||||||
|
@ -981,6 +1011,7 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
||||||
|
|
||||||
def _ErrorCB(self, con, iq_obj):
|
def _ErrorCB(self, con, iq_obj):
|
||||||
log.debug('ErrorCB')
|
log.debug('ErrorCB')
|
||||||
|
ConnectionHandlersBase._ErrorCB(self, con, iq_obj)
|
||||||
jid_from = helpers.get_full_jid_from_iq(iq_obj)
|
jid_from = helpers.get_full_jid_from_iq(iq_obj)
|
||||||
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(jid_from)
|
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(jid_from)
|
||||||
id_ = unicode(iq_obj.getID())
|
id_ = unicode(iq_obj.getID())
|
||||||
|
@ -988,10 +1019,6 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
||||||
self.dispatch('OS_INFO', (jid_stripped, resource, '', ''))
|
self.dispatch('OS_INFO', (jid_stripped, resource, '', ''))
|
||||||
self.version_ids.remove(id_)
|
self.version_ids.remove(id_)
|
||||||
return
|
return
|
||||||
if id_ in self.last_ids:
|
|
||||||
self.dispatch('LAST_STATUS_TIME', (jid_stripped, resource, -1, ''))
|
|
||||||
self.last_ids.remove(id_)
|
|
||||||
return
|
|
||||||
if id_ in self.entity_time_ids:
|
if id_ in self.entity_time_ids:
|
||||||
self.dispatch('ENTITY_TIME', (jid_stripped, resource, ''))
|
self.dispatch('ENTITY_TIME', (jid_stripped, resource, ''))
|
||||||
self.entity_time_ids.remove(id_)
|
self.entity_time_ids.remove(id_)
|
||||||
|
@ -1132,26 +1159,6 @@ ConnectionCaps, ConnectionHandlersBase, ConnectionJingle):
|
||||||
self.connection.send(iq_obj)
|
self.connection.send(iq_obj)
|
||||||
raise common.xmpp.NodeProcessed
|
raise common.xmpp.NodeProcessed
|
||||||
|
|
||||||
def _LastResultCB(self, con, iq_obj):
|
|
||||||
log.debug('LastResultCB')
|
|
||||||
qp = iq_obj.getTag('query')
|
|
||||||
seconds = qp.getAttr('seconds')
|
|
||||||
status = qp.getData()
|
|
||||||
try:
|
|
||||||
seconds = int(seconds)
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
id_ = iq_obj.getID()
|
|
||||||
if id_ in self.groupchat_jids:
|
|
||||||
who = self.groupchat_jids[id_]
|
|
||||||
del self.groupchat_jids[id_]
|
|
||||||
else:
|
|
||||||
who = helpers.get_full_jid_from_iq(iq_obj)
|
|
||||||
if id_ in self.last_ids:
|
|
||||||
self.last_ids.remove(id_)
|
|
||||||
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who)
|
|
||||||
self.dispatch('LAST_STATUS_TIME', (jid_stripped, resource, seconds, status))
|
|
||||||
|
|
||||||
def _VersionResultCB(self, con, iq_obj):
|
def _VersionResultCB(self, con, iq_obj):
|
||||||
log.debug('VersionResultCB')
|
log.debug('VersionResultCB')
|
||||||
client_info = ''
|
client_info = ''
|
||||||
|
|
|
@ -30,6 +30,8 @@ from common.xmpp.protocol import *
|
||||||
import socket
|
import socket
|
||||||
import errno
|
import errno
|
||||||
import sys
|
import sys
|
||||||
|
import string
|
||||||
|
from random import Random
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger('gajim.c.z.client_zeroconf')
|
log = logging.getLogger('gajim.c.z.client_zeroconf')
|
||||||
|
@ -412,7 +414,6 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
|
|
||||||
If supplied data is unicode string, encode it to UTF-8.
|
If supplied data is unicode string, encode it to UTF-8.
|
||||||
"""
|
"""
|
||||||
print 'ici'
|
|
||||||
if self.state <= 0:
|
if self.state <= 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -726,7 +727,8 @@ class ClientZeroconf:
|
||||||
def send(self, stanza, is_message=False, now=False, on_ok=None,
|
def send(self, stanza, is_message=False, now=False, on_ok=None,
|
||||||
on_not_ok=None):
|
on_not_ok=None):
|
||||||
stanza.setFrom(self.roster.zeroconf.name)
|
stanza.setFrom(self.roster.zeroconf.name)
|
||||||
to = stanza.getTo()
|
to = unicode(stanza.getTo())
|
||||||
|
to = gajim.get_jid_without_resource(to)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
item = self.roster[to]
|
item = self.roster[to]
|
||||||
|
@ -759,6 +761,12 @@ class ClientZeroconf:
|
||||||
P2PClient(None, item['address'], item['port'], self,
|
P2PClient(None, item['address'], item['port'], self,
|
||||||
[(stanza, is_message)], to, on_ok=on_ok, on_not_ok=on_not_ok)
|
[(stanza, is_message)], to, on_ok=on_ok, on_not_ok=on_not_ok)
|
||||||
|
|
||||||
|
def getAnID(self):
|
||||||
|
"""
|
||||||
|
Generate a random id
|
||||||
|
"""
|
||||||
|
''.join(Random().sample(string.letters + string.digits, 6))
|
||||||
|
|
||||||
def RegisterDisconnectHandler(self, handler):
|
def RegisterDisconnectHandler(self, handler):
|
||||||
"""
|
"""
|
||||||
Register handler that will be called on disconnect
|
Register handler that will be called on disconnect
|
||||||
|
|
Loading…
Reference in New Issue