Beispiel #1
0
    def handle(self, tree):
        """handler for resence requests,
           returns a response that should be sent back"""
        log.debug('loading roster to broadcast presence to subscribers..')
        session = Session()
        response = list()
        senderjid = JID(tree.get("from"))
        roster = session.query(Roster).filter_by(jid=senderjid.bare).first()
        if roster is not None:
            for contact in roster.contacts:
                # only broadcast to contacts having from or both subscription to brodcasting contact..
                if contact.subscription not in ['from', 'both']:
                    continue
                log.debug('broadcasting presence to ' + contact.jid.bare)
                brd_element = copy.deepcopy(tree)
                brd_element.set('to', contact.jid.bare)
                response.append(brd_element)

        # also broadcast presence to bare JID so all resources gets it
        brd_element = copy.deepcopy(tree)
        brd_element.set('to', JID(tree.get('from')).bare)
        response.append(brd_element)

        return response
Beispiel #2
0
    def handle(self, tree):
        """handler for resence requests,
           returns a response that should be sent back"""
        log.debug('loading roster to broadcast presence to subscribers..')
        session = Session()
        response = list()
        senderjid = JID(tree.get("from"))
        roster = session.query(Roster).filter_by(jid=senderjid.bare).first()
        if roster is not None:
            for contact in roster.contacts:
                # only broadcast to contacts having from or both subscription to brodcasting contact..
                if contact.subscription not in ['from', 'both']:
                    continue
                log.debug('broadcasting presence to ' + contact.jid.bare)
                brd_element = copy.deepcopy(tree)
                brd_element.set('to', contact.jid.bare )
                response.append(brd_element)

        # also broadcast presence to bare JID so all resources gets it
        brd_element = copy.deepcopy(tree)
        brd_element.set('to', JID(tree.get('from')).bare )
        response.append(brd_element)

        return response
Beispiel #3
0
    def roster(self):
        """RFC6121 Section 2"""

        session = Session()
        senderjid = JID(self.sender)
        roster = session.query(Roster).filter_by(jid=senderjid.bare).first()
        if roster is None:
            roster = Roster(jid=senderjid.bare)
            session.add(roster)
            session.commit()

        for contact in roster.contacts:
            self.response.append(contact.to_element())
        self.response.set("xmlns", """jabber:iq:roster""")
Beispiel #4
0
    def roster(self):
        """RFC6121 Section 2"""

        session = Session()
        senderjid = JID(self.sender)
        roster = session.query(Roster).filter_by(jid=senderjid.bare).first()
        if roster is None:
            roster = Roster(jid=senderjid.bare)
            session.add(roster)
            session.commit()

        for contact in roster.contacts:
            self.response.append(contact.to_element())
        self.response.set("xmlns", """jabber:iq:roster""")