changeset be4f8698ac8d in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=be4f8698ac8d
description: ability to send jabber:iq:last query over zeroconf. Fixes #5644
diffstat:
src/common/connection.py | 39 +++++++++------------
src/common/connection_handlers.py | 59 +++++++++++++++++++--------------
src/common/zeroconf/client_zeroconf.py | 12 +++++-
3 files changed, 60 insertions(+), 50 deletions(-)
diffs (202 lines):
diff -r e0912fe3fd94 -r be4f8698ac8d src/common/connection.py
--- a/src/common/connection.py Wed Mar 10 13:52:54 2010 +0100
+++ b/src/common/connection.py Wed Mar 10 21:58:14 2010 +0100
@@ -509,11 +509,25 @@
def account_changed(self, 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):
"""
@@ -1756,25 +1770,6 @@
self.connection = con
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):
"""
groupchat_jid is used when we want to send a request to a real jid and
diff -r e0912fe3fd94 -r be4f8698ac8d src/common/connection_handlers.py
--- a/src/common/connection_handlers.py Wed Mar 10 13:52:54 2010 +0100
+++ b/src/common/connection_handlers.py Wed Mar 10 21:58:14 2010 +0100
@@ -782,10 +782,42 @@
# keep the jids we auto added (transports contacts) to not send the
# SUBSCRIBED event to gui
self.automatically_added = []
+ # IDs of jabber:iq:last requests
+ self.last_ids = []
# keep track of sessions this connection has with other JIDs
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):
"""
Get all sessions for the given full jid
@@ -936,8 +968,6 @@
# keep the latest subscribed event for each jid to prevent loop when we
# acknowledge presences
self.subscribed_events = {}
- # IDs of jabber:iq:last requests
- self.last_ids = []
# IDs of jabber:iq:version requests
self.version_ids = []
# IDs of urn:xmpp:time requests
@@ -981,6 +1011,7 @@
def _ErrorCB(self, con, iq_obj):
log.debug('ErrorCB')
+ ConnectionHandlersBase._ErrorCB(self, con, iq_obj)
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())
@@ -988,10 +1019,6 @@
self.dispatch('OS_INFO', (jid_stripped, resource, '', ''))
self.version_ids.remove(id_)
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:
self.dispatch('ENTITY_TIME', (jid_stripped, resource, ''))
self.entity_time_ids.remove(id_)
@@ -1132,26 +1159,6 @@
self.connection.send(iq_obj)
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):
log.debug('VersionResultCB')
client_info = ''
diff -r e0912fe3fd94 -r be4f8698ac8d src/common/zeroconf/client_zeroconf.py
--- a/src/common/zeroconf/client_zeroconf.py Wed Mar 10 13:52:54 2010 +0100
+++ b/src/common/zeroconf/client_zeroconf.py Wed Mar 10 21:58:14 2010 +0100
@@ -30,6 +30,8 @@
import socket
import errno
import sys
+import string
+from random import Random
import logging
log = logging.getLogger('gajim.c.z.client_zeroconf')
@@ -412,7 +414,6 @@
If supplied data is unicode string, encode it to UTF-8.
"""
- print 'ici'
if self.state <= 0:
return
@@ -726,7 +727,8 @@
def send(self, stanza, is_message=False, now=False, on_ok=None,
on_not_ok=None):
stanza.setFrom(self.roster.zeroconf.name)
- to = stanza.getTo()
+ to = unicode(stanza.getTo())
+ to = gajim.get_jid_without_resource(to)
try:
item = self.roster[to]
@@ -759,6 +761,12 @@
P2PClient(None, item['address'], item['port'], self,
[(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):
"""
Register handler that will be called on disconnect
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits