Esempio n. 1
0
    def bind(self, resource):
        while self.bound is None and self.owner.process(1):
            pass

        resource = Node('resource', payload=[resource])
        res = self.owner.Dispatcher.send_and_wait_for_response(
            Protocol('iq',
                     tye='set',
                     payload=[
                         Node('bind',
                              attrs={'xmlns': NS_BIND},
                              payload=[resource])
                     ]))
        if is_result_node(res):
            self.bound.append(res.get_tag('bind').get_tag_data('jid'))
            jid = JID(res.get_tag('bind').get_tag_data('jid'))
            self.owner.user = jid.get_node()
            self.owner.resource = jid.get_resource()
            self.enable()
            res = self.owner.Dispatcher.send_and_wait_for_response(
                Protocol(
                    'iq',
                    tye='set',
                    payload=[Node('session', attrs={'xmlns': NS_SESSION})]))
            if is_result_node(res):
                self.session = 1
                return 'ok'
            else:
                self.session = 0
        else:
            return ''
Esempio n. 2
0
    def PresenceHandler(self, dis, pres):
        """
        Presence tracker. Used internally for setting items' resources state in
        internal roster representation
        """
        if pres.getTag('x', namespace=NS_MUC_USER):
            return
        jid=pres.getFrom()
        if not jid:
            # If no from attribue, it's from server
            jid=self._owner.Server
        jid=JID(jid)
        if not self._data.has_key(jid.getStripped()): self._data[jid.getStripped()]={'name':None,'ask':None,'subscription':'none','groups':['Not in roster'],'resources':{}}
        if type(self._data[jid.getStripped()]['resources'])!=type(dict()):
            self._data[jid.getStripped()]['resources']={}
        item=self._data[jid.getStripped()]
        typ=pres.getType()

        if not typ:
            log.info('Setting roster item %s for resource %s...'%(jid.getStripped(), jid.getResource()))
            item['resources'][jid.getResource()]=res={'show':None,'status':None,'priority':'0','timestamp':None}
            if pres.getTag('show'): res['show']=pres.getShow()
            if pres.getTag('status'): res['status']=pres.getStatus()
            if pres.getTag('priority'): res['priority']=pres.getPriority()
            if not pres.getTimestamp(): pres.setTimestamp()
            res['timestamp']=pres.getTimestamp()
        elif typ=='unavailable' and item['resources'].has_key(jid.getResource()): del item['resources'][jid.getResource()]
Esempio n. 3
0
    def bind(self, resource):
        while self.bound is None and self.owner.process(1):
            pass

        resource = Node('resource', payload=[resource])
        res = self.owner.Dispatcher.send_and_wait_for_response(Protocol('iq', tye='set',
                                                                        payload=[Node('bind', attrs={'xmlns': NS_BIND}, payload=[resource])]))
        if is_result_node(res):
            self.bound.append(res.get_tag('bind').get_tag_data('jid'))
            jid = JID(res.get_tag('bind').get_tag_data('jid'))
            self.owner.user = jid.get_node()
            self.owner.resource = jid.get_resource()
            self.enable()
            res = self.owner.Dispatcher.send_and_wait_for_response(Protocol('iq', tye='set',
                                                                            payload=[Node('session', attrs={'xmlns': NS_SESSION})]))
            if is_result_node(res):
                self.session = 1
                return 'ok'
            else:
                self.session = 0
        else:
            return ''