diff plugins/plugin_xep_0096.py @ 15:218ec9984fa5

wokkel integration part III + memory saved again - disco handler (plugins handled)
author Goffi <goffi@goffi.org>
date Sat, 31 Oct 2009 00:18:35 +0100
parents 4b05308d45f9
children f2a745ca0fbc
line wrap: on
line diff
--- a/plugins/plugin_xep_0096.py	Fri Oct 30 20:05:25 2009 +0100
+++ b/plugins/plugin_xep_0096.py	Sat Oct 31 00:18:35 2009 +0100
@@ -27,6 +27,19 @@
 from twisted.internet import reactor #FIXME best way ???
 import pdb
 
+from zope.interface import implements
+
+try:
+    from twisted.words.protocols.xmlstream import XMPPHandler
+except ImportError:
+    from wokkel.subprotocols import XMPPHandler
+
+from wokkel import disco, iwokkel
+
+IQ_SET = '/iq[@type="set"]'
+NS_SI = 'http://jabber.org/protocol/si'
+SI_REQUEST = IQ_SET + '/si[@xmlns="' + NS_SI + '"]'
+
 PLUGIN_INFO = {
 "name": "XEP 0096 Plugin",
 "import_name": "XEP_0096",
@@ -36,16 +49,28 @@
 "description": """Implementation of SI File Transfert"""
 }
 
-class XEP_0096:
+class XEP_0096(XMPPHandler):
+    implements(iwokkel.IDisco)
+    
     def __init__(self, host):
         info("Plugin XEP_0096 initialization")
         self.host = host
         self._waiting_for_approval = {}
-        host.add_IQ_cb("http://jabber.org/protocol/si", self.xep_96)
         host.bridge.addMethod("sendFile", ".communication", in_sign='ss', out_sign='s', method=self.sendFile)
     
+    def connectionInitialized(self):
+        self.xmlstream.addObserver(SI_REQUEST, self.xep_96)
+
+
+    def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
+        return [disco.DiscoFeature(NS_SI)]
+
+    def getDiscoItems(self, requestor, target, nodeIdentifier=''):
+        return []
+
     def xep_96(self, IQ):
         info ("XEP-0096 management")
+        IQ.handled=True
         SI_elem = IQ.firstChildElement()
         debug(SI_elem.toXml())
         filename = ""