From 66e7ea153e975a0bf2a3508f09bb06aaf68a5eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=ABl=20Verrier?= Date: Wed, 15 Jul 2009 15:13:12 +0200 Subject: [PATCH] * now we handle result for archiving preferences request and also all changes that come from server --- src/common/connection.py | 7 +++++ src/common/connection_handlers.py | 5 ++- src/common/message_archiving.py | 52 ++++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index d09846c49..d134b1818 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1032,6 +1032,13 @@ class Connection(ConnectionHandlers): self.connection.set_send_timeout(self.keepalives, self.send_keepalive) self.connection.set_send_timeout2(self.pingalives, self.sendPing) self.connection.onreceive(None) + + # Request message archiving preferences + iq = common.xmpp.Iq('get') + iq.setTag('pref', namespace=common.xmpp.NS_ARCHIVE) + self.connection.send(iq) + + # Request privacy list iq = common.xmpp.Iq('get', common.xmpp.NS_PRIVACY, xmlns = '') id_ = self.connection.getAnID() iq.setID(id_) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 0c3ab981f..ed20e0618 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -51,6 +51,7 @@ from common import exceptions from common.commands import ConnectionCommands from common.pubsub import ConnectionPubSub from common.caps import ConnectionCaps +from common.message_archiving import ConnectionArchive from common import dbus_support if dbus_support.supported: @@ -1433,8 +1434,9 @@ sent a message to.''' return sess -class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub, ConnectionCaps, ConnectionHandlersBase): +class ConnectionHandlers(ConnectionArchive, ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub, ConnectionCaps, ConnectionHandlersBase): def __init__(self): + ConnectionArchive.__init__(self) ConnectionVcard.__init__(self) ConnectionBytestream.__init__(self) ConnectionCommands.__init__(self) @@ -2739,6 +2741,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, common.xmpp.NS_SEARCH) con.RegisterHandler('iq', self._PrivacySetCB, 'set', common.xmpp.NS_PRIVACY) + con.RegisterHandler('iq', self._ArchiveCB, ns=common.xmpp.NS_ARCHIVE) con.RegisterHandler('iq', self._PubSubCB, 'result') con.RegisterHandler('iq', self._ErrorCB, 'error') con.RegisterHandler('iq', self._IqCB) diff --git a/src/common/message_archiving.py b/src/common/message_archiving.py index b11b7e779..e28691890 100644 --- a/src/common/message_archiving.py +++ b/src/common/message_archiving.py @@ -19,7 +19,7 @@ ## -class ArchivingPreferences: +class ConnectionArchive: def __init__(self): self.auto_save = None self.method_auto = None @@ -28,17 +28,53 @@ class ArchivingPreferences: self.default = None self.items = {} - def set(self, auto_save, method_auto, method_local, method_manual): - self.auto_save = auto_save - self.method_auto = method_auto - self.method_local = method_local - self.method_manual = method_manual - def set_default(self, otr, save, expire=None, unset=False): - self.default = {'expire': expire, 'otr': otr, 'save': save, 'unset': unset} + self.default = {'expire': expire, 'otr': otr, 'save': save, + 'unset': unset} def append_or_update_item(self, jid, expire, otr, save): self.items[jid] = {'expire': expire, 'otr': otr, 'save': save} def remove_item(self, jid): del self.items[jid] + + def _ArchiveCB(self, con, iq_obj): + print '_ArchiveCB', iq_obj.getType() + if iq_obj.getType() not in ('result', 'set'): + return + if iq_obj.getTag('pref'): + pref = iq_obj.getTag('pref') + + if pref.getTag('auto'): + self.auto_save = pref.getTagAttr('auto', 'save') + print 'auto_save:', self.auto_save + + method_auto = pref.getTag('method', attrs={'type': 'auto'}) + if method_auto: + self.method_auto = method_auto.getAttr('use') + + method_local = pref.getTag('method', attrs={'type': 'local'}) + if method_local: + self.method_local = method_local.getAttr('use') + + method_manual = pref.getTag('method', attrs={'type': 'manual'}) + if method_manual: + self.method_manual = method_manual.getAttr('use') + + print 'method alm:', self.method_auto, self.method_local, self.method_manual + + if pref.getTag('default'): + default = pref.getTag('default') + print 'default oseu:', default.getAttr('otr'), default.getAttr('save'), default.getAttr('expire'), default.getAttr('unset') + self.set_default(default.getAttr('otr'), + default.getAttr('save'), default.getAttr('expire'), + default.getAttr('unset')) + for item in pref.getTags('item'): + print item.getAttr('jid'), item.getAttr('otr'), item.getAttr('save'), item.getAttr('expire') + self.append_or_update_item(item.getAttr('jid'), + item.getAttr('otr'), item.getAttr('save'), + item.getAttr('expire')) + elif iq_obj.getTag('itemremove'): + for item in pref.getTags('item'): + print 'del', item.getAttr('jid') + self.remove_item(item.getAttr('jid'))