diff plugins/plugin_xep_0100.py @ 39:2e3411a6baad

Wix: external server management in gateways manager, SàT: bug fixes in gateway management - SàT: from twisted.words.protocols.jabber.error module imported as jab_error to avoir name colision with error log method - XEP_0100 plugin: added errback for disco info - XEP_0077 plugin: registration callback now look for "x" element (data form: see XEP-0004), and send an error message if it can't find it. - Wix: added fields for browsing external server gateways
author Goffi <goffi@goffi.org>
date Thu, 17 Dec 2009 17:29:02 +1100
parents a61beb21d16d
children 874de3020e1c
line wrap: on
line diff
--- a/plugins/plugin_xep_0100.py	Thu Dec 17 13:13:13 2009 +1100
+++ b/plugins/plugin_xep_0100.py	Thu Dec 17 17:29:02 2009 +1100
@@ -21,7 +21,8 @@
 
 from logging import debug, info, error
 from twisted.internet import protocol
-from twisted.words.protocols.jabber import client, jid, xmlstream, error
+from twisted.words.protocols.jabber import client, jid, xmlstream
+from twisted.words.protocols.jabber import error as jab_error
 import pdb
 
 from wokkel import disco, iwokkel
@@ -43,7 +44,17 @@
         self.__gateways = {}  #dict used to construct the answer to findGateways. Key = target jid
         host.bridge.addMethod("findGateways", ".communication", in_sign='s', out_sign='s', method=self.findGateways)
         host.bridge.addMethod("gatewayRegister", ".request", in_sign='ssa(ss)', out_sign='s', method=self.gatewayRegister)
-    
+
+    def __inc_handled_items(self, request_id):
+        self.__gateways[request_id]['__handled_items']+=1
+
+        if self.__gateways[request_id]['__total_items'] == self.__gateways[request_id]['__handled_items']:
+            debug ("All items checked for id [%s]" % str(request_id))
+            
+            del self.__gateways[request_id]['__total_items']
+            del self.__gateways[request_id]['__handled_items']
+            self.host.actionResultExt(request_id,"DICT_DICT",self.__gateways[request_id])
+
     def discoInfo(self, disco, entity, request_id):
         """Find disco infos about entity, to check if it is a gateway"""
 
@@ -55,14 +66,14 @@
                     'type':identity[1]
                 }
 
-        self.__gateways[request_id]['__handled_items']+=1
-
-        if self.__gateways[request_id]['__total_items'] == self.__gateways[request_id]['__handled_items']:
-            debug ("All items checked for id [%s]" % str(request_id))
-            
-            del self.__gateways[request_id]['__total_items']
-            del self.__gateways[request_id]['__handled_items']
-            self.host.actionResultExt(request_id,"DICT_DICT",self.__gateways[request_id])
+        self.__inc_handled_items(request_id)
+    
+    def discoInfoErr(self, failure, entity, request_id):
+        """Something is going wrong with disco"""
+        failure.trap(jab_error.StanzaError)
+        error("Error when discovering [%s]: %s" % (entity.full(), failure.value.condition))
+        self.__inc_handled_items(request_id)
+        
     
     def discoItems(self, disco, request_id):
         """Look for items with disco protocol, and ask infos for each one"""
@@ -76,6 +87,7 @@
         for item in disco._items:
             debug ("item found: %s", item.name)
             self.host.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id)
+            self.host.disco.requestInfo(item.entity).addErrback(self.discoInfoErr, entity=item.entity, request_id=request_id)
 
     def registrationSuccessful(self, target):
         """Called when in_band registration is ok, we must now follow the rest of procedure"""