Exemplo n.º 1
0
    def presenceChanged(self,user,comp_name,domain,status):
        """
        Processs change of presence of user

        It publshes items or pubsub node which should be persistent
        Every item is published with id == username (jid without resource)
        this means, that in case if update node will be atomaticaly
        replaced with new value, no need to delete and recreate node
        """
        
        def process_dns(dnsresult,userstats):
            try:
                hostname = str(dnsresult[0][0].payload.name)
            except:
                #DNS error happens, publish empty hostname
                hostname = ""

            username = userstats['username']
            userstats['hostname'] = hostname
            #make new item which would be published
            #TODO: serializing and deserializing should take place in separate func
            payload = domish.Element((None,"user"))
            for k,v in userstats.items():
                payload[k] = v
                
            item = Item(id=username,payload=payload)
            log.msg("Publishing presence of %s"%username)
            self.pubsub_client.publish(JID("pubsub.%s"%self.domain),PUB_NODE,items=[item],sender=JID(self.name))
                       
        def process_newpresence(userstats,status):
            """
            publish new payload
            """            
            userstats['status'] = status
            username = userstats['username']
        
            #build reverse ip name for DNS query
            reverse_ip = '.'.join(userstats['ip'].split('.')[::-1])+'.in-addr.arpa.'
            d = self.dns_client.lookupPointer(reverse_ip)
            d.addBoth(process_dns,userstats)
          
        #simply delete node if user offline, request details otherwise
        if status == 'offline':
            username = user.userhost()
            request = PubSubRequestWithConf('retract')
            request.recipient = JID(self.pubsub_name)
            request.nodeIdentifier = PUB_NODE
            request.sender = JID(self.name)
            request.itemIdentifiers = [username]
            log.msg("User %s goes offline, retracting published node"%username)
            request.send(self.xmlstream)
        else:           
            d = self.get_userstats(user,comp_name,domain)
            d.addCallback(process_newpresence,status)        
Exemplo n.º 2
0
 def configure_node(data):
     request = PubSubRequestWithConf('configureSet')
     request.recipient = JID(self.pubsub_name)
     request.nodeIdentifier = PUB_NODE
     request.sender = JID(self.name)
     
     frm = Form('submit')
     frm.addField( Field(fieldType='hidden',var='FORM_TYPE',value=NS_PUBSUB_NODE_CONFIG) )
     frm.addField( Field(var='pubsub#title',value='Live presence events') )
     frm.addField( Field(var='pubsub#persist_items',value='1') )
     frm.addField( Field(var='pubsub#deliver_payloads',value='1') )
     frm.addField( Field(var='pubsub#send_last_published_item',value='never') )
     frm.addField( Field(var='pubsub#presence_based_delivery',value='0') )
     frm.addField( Field(var='pubsub#access_model',value='open') )
     frm.addField( Field(var='pubsub#node_type',value='leaf') )
     frm.addField( Field(var='pubsub#max_items',value='100') )
     
     request.configureForm = frm
     request.send(self.xmlstream)
Exemplo n.º 3
0
    def initial_publish(self):
        """
        purges currently published items on persistent node, then asks all users to send presence data again
        """
        
        def process_online_users(items):
            log.msg("Sending probe to all online users")
            for user in items:
                self.probe(user.entity,sender=JID(self.name))
                self.available(user.entity,sender=JID(self.name))

        #purge all published items under persistent node
        #client to this node will be notified about node purge
        request = PubSubRequestWithConf('purge')
        request.recipient = JID(self.pubsub_name)
        request.nodeIdentifier = PUB_NODE
        request.sender = JID(self.name)
        d = request.send(self.xmlstream)

        log.msg("Requesting list of online users")
        d = self.disco_client.requestItems(JID(self.domain),NODE_ONLINE_USERS, sender=JID(self.name))
        d.addCallback(process_online_users)