Changeset 748

Show
Ignore:
Timestamp:
07/28/08 15:13:17 (4 months ago)
Author:
sylvain
Message:

Finished support for Node information retrieval
Better handling of errors on http://jabber.org/protocol/disco#info namespace

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • oss/headstock/headstock/api/discovery.py

    r746 r748  
    118118                    elif i.xml_ns == XMPP_DATA_FORM_NS: 
    119119                        disco.data_form = Data.from_element(i) 
     120            elif c.xml_ns == XMPP_CLIENT_NS and c.xml_name == 'error': 
     121                disco.error = Error.from_element(c) 
    120122 
    121123        return disco 
     
    251253    def __init__(self, from_jid, to_jid, node_name=None, type=u'get', stanza_id=None): 
    252254        Entity.__init__(self, from_jid, to_jid, type, stanza_id) 
     255        self.data_form = None 
    253256        self.node_name = node_name 
     257        self.identities = [] 
     258        self.features = [] 
     259        self.items = [] 
    254260     
    255261    @staticmethod 
     
    265271    def from_element(e): 
    266272        disco = InformationDiscovery(JID.parse(e.get_attribute_value('from')), 
    267                                    JID.parse(e.get_attribute_value('to')), 
    268                                    type=e.get_attribute_value('type'), 
    269                                    stanza_id=e.get_attribute_value('id')) 
    270  
    271         return disco 
     273                                     JID.parse(e.get_attribute_value('to')), 
     274                                     type=e.get_attribute_value('type'), 
     275                                     stanza_id=e.get_attribute_value('id')) 
     276 
     277        for c in e.xml_children: 
     278            if not isinstance(c, E): 
     279                continue 
     280             
     281            if c.xml_ns in [XMPP_DISCO_INFO_NS, XMPP_DISCO_ITEMS_NS]: 
     282                disco.node_name = c.get_attribute_value('node') 
     283                for i in c.xml_children: 
     284                    if i.xml_ns in [XMPP_DISCO_INFO_NS, XMPP_DISCO_ITEMS_NS]: 
     285                        if i.xml_name == 'identity': 
     286                            ident = Identity(i.get_attribute_value('name'), 
     287                                             i.get_attribute_value('category'), 
     288                                             i.get_attribute_value('type')) 
     289                            disco.identities.append(ident) 
     290                        elif i.xml_name == 'feature': 
     291                            feat = Feature(i.get_attribute_value('var')) 
     292                            disco.features.append(feat) 
     293                        elif i.xml_name == 'item': 
     294                            jid = JID.parse(unicode(i.get_attribute_value('jid'))) 
     295                            item = Item(jid, i.get_attribute_value('action'), 
     296                                        i.get_attribute_value('name'), 
     297                                        i.get_attribute_value('node')) 
     298                            disco.items.append(item) 
     299                    elif i.xml_ns == XMPP_DATA_FORM_NS: 
     300                        disco.data_form = Data.from_element(i) 
     301            elif c.xml_ns == XMPP_CLIENT_NS and c.xml_name == 'error': 
     302                disco.error = Error.from_element(c) 
     303        return disco 
  • oss/headstock/headstock/protocol/extension/discovery.py

    r746 r748  
    99from Axon.Component import component 
    1010from Axon.Ipc import shutdownMicroprocess, producerFinished 
     11from Kamaelia.Util.Fanout import Fanout 
    1112 
    1213 
     
    5152                handled = False 
    5253                a = self.recv("inbox") 
    53                 e = a.xml_parent  
    54                 self.send(('INCOMING', e), "log") 
    55                  
    56                 msg_type = e.get_attribute_value(u'type') or u'get' 
    57                 key = 'xmpp.%s' % unicode(msg_type) 
    58  
    59                 if key in self.outboxes: 
    60                     self.send(FeaturesDiscovery.from_element(e), key) 
    61                     handled = True 
    62  
    63                 if not handled: 
    64                     self.send(e, "unknown") 
     54                if a.get_attribute_value(u'node') == None: 
     55                    e = a.xml_parent  
     56                    self.send(('INCOMING', e), "log") 
     57 
     58                    msg_type = e.get_attribute_value(u'type') or u'get' 
     59                    key = 'xmpp.%s' % unicode(msg_type) 
     60 
     61 
     62                    if key in self.outboxes: 
     63                        self.send(FeaturesDiscovery.from_element(e), key) 
     64                        handled = True 
     65 
     66                    if not handled: 
     67                        self.send(e, "unknown") 
    6568 
    6669            if not self.anyReady(): 
     
    269272                handled = False 
    270273                s = self.recv("inbox") 
    271                 e = s.xml_parent.xml_parent 
    272                 self.send(('INCOMING', e), "log") 
    273                  
    274                 msg_type = e.get_attribute_value(u'type') or u'get' 
    275                 key = 'xmpp.%s' % unicode(msg_type) 
    276  
    277                 if key in self.outboxes: 
    278                     self.send(InformationDiscovery.from_element(e), key) 
    279                     handled = True 
    280  
    281                 if not handled: 
    282                     self.send(e, "unknown") 
     274                if s.get_attribute_value(u'node') != None: 
     275                    e = s.xml_parent 
     276                    self.send(('INCOMING', e), "log") 
     277 
     278                    msg_type = e.get_attribute_value(u'type') or u'get' 
     279                    key = 'xmpp.%s' % unicode(msg_type) 
     280                    if key in self.outboxes: 
     281                        self.send(InformationDiscovery.from_element(e), key) 
     282                        handled = True 
     283 
     284                    if not handled: 
     285                        self.send(e, "unknown") 
    283286 
    284287            if not self.anyReady(): 
     
    361364        super(DiscoveryDispatcher, self).__init__()  
    362365 
    363     def initComponents(self):         
     366    def initComponents(self):  
     367        fanout = Fanout(["features", "info"]) 
     368        self.link((self, 'inbox'), (fanout, 'inbox'), passthrough=1) 
     369        self.addChildren(fanout) 
     370        fanout.activate() 
     371         
    364372        subdisp = SubscriptionsDiscoveryDispatcher() 
    365373        self.link((self, 'subscription.inbox'), (subdisp, 'inbox'), passthrough=1) 
     
    397405     
    398406        featdisp = FeaturesDiscoveryDispatcher() 
     407        self.link((fanout, 'features'), (featdisp, 'inbox')) 
    399408        self.link((self, 'features.inbox'), (featdisp, 'inbox'), passthrough=1) 
    400409        self.link((self, 'features.forward'), (featdisp, 'forward'), passthrough=1) 
     
    431440 
    432441        infodisp = InformationDiscoveryDispatcher() 
     442        self.link((fanout, 'info'), (infodisp, 'inbox')) 
    433443        self.link((self, 'info.inbox'), (infodisp, 'inbox'), passthrough=1) 
    434444        self.link((self, 'info.forward'), (infodisp, 'forward'), passthrough=1) 
     
    456466                mes = self.recv("control") 
    457467                 
    458                 if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): 
     468                if isinstance(mes, shutdownMicroprocess) or \ 
     469                        isinstance(mes, producerFinished): 
    459470                    self.send(producerFinished(), "signal") 
    460471                    break 
  • oss/headstock/headstock/protocol/extension/pubsub.py

    r739 r748  
    788788                mes = self.recv("control") 
    789789                 
    790                 if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): 
    791                     self.send(producerFinished(), "signal") 
    792                     break 
    793  
    794             if not self.anyReady(): 
    795                 self.pause() 
    796    
    797             yield 1 
    798  
    799         yield 1 
     790                if isinstance(mes, shutdownMicroprocess) or \ 
     791                        isinstance(mes, producerFinished): 
     792                    self.send(producerFinished(), "signal") 
     793                    break 
     794 
     795            if not self.anyReady(): 
     796                self.pause() 
     797   
     798            yield 1 
     799 
     800        yield 1