コード例 #1
0
            if barejid in self.xmpp.roster and (
                    self.xmpp.roster[barejid]['subscription']
                    in ('from', 'both') or barejid == self.xmpp.boundjid.bare):
                # We don't know how to calculate it
                iq.reply().error().setPayload(iq['last_activity'].xml)
                iq['error']['code'] = '503'
                iq['error']['type'] = 'cancel'
                iq['error']['condition'] = 'service-unavailable'
                iq.send()
            else:
                iq.reply().error().setPayload(iq['last_activity'].xml)
                iq['error']['code'] = '403'
                iq['error']['type'] = 'auth'
                iq['error']['condition'] = 'forbidden'
                iq.send()

    def get_last_activity(self, jid):
        """Query the LastActivity of jid and return it in seconds"""
        iq = self.xmpp.makeIqGet()
        query = LastActivity()
        iq.append(query.xml)
        iq.attrib['to'] = jid
        iq.attrib['from'] = self.xmpp.boundjid.full
        id = iq.get('id')
        result = iq.send()
        return result['last_activity']['seconds']


xep_0012 = XEP_0012
register_plugin(XEP_0012)
コード例 #2
0
        self.xmpp.register_feature('compression',
                self._handle_compression,
                restart=True,
                order=self.config.get('order', 5))

    def register_compression_method(self, name, handler):
        self.compression_methods[name] = handler

    def _handle_compression(self, features):
        for method in features['compression']['methods']:
            if method in self.compression_methods:
                log.info('Attempting to use %s compression' % method)
                c = Compress(self.xmpp)
                c['method'] = method
                c.send(now=True)
                return True
        return False

    def _handle_compressed(self, stanza):
        self.xmpp.features.add('compression')
        log.debug('Stream Compressed!')
        compressed_socket = ZlibSocket(self.xmpp.socket)
        self.xmpp.set_socket(compressed_socket)
        raise RestartStream()

    def _handle_failure(self, stanza):
        pass

xep_0138 = XEP_0138
register_plugin(XEP_0138)
コード例 #3
0
ファイル: chat_voting.py プロジェクト: legastero/memberbot
        if msg['type'] not in ('normal', 'chat'):
            return
        if not self.xmpp['xsf_roster'].is_member(user):
            log.warn('Unkown user: %s', user)
            return

        if user not in self.sessions:
            self.sessions[user] = VotingSession(self.xmpp, user)
        session = self.sessions[user]
        try:
            session.process(msg['body'], )
        except StopIteration:
            pass


register_plugin(XSFVotingChat)


class VotingSession(object):

    def __init__(self, xmpp, user):
        self.xmpp = xmpp
        self.user = user
        self._session = self._process()
        self._session.next()

    def end(self):
        name = self.xmpp.client_roster[self.user]['name'] or self.user.bare
        self.send('end')
        del self.xmpp['xsf_voting_chat'].sessions[self.user]
コード例 #4
0
"""
    SleekXMPP: The Sleek XMPP Library
    Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
    This file is part of SleekXMPP.

    See the file LICENSE for copying permission.
"""

from sleekxmpp.plugins import BasePlugin, register_plugin


class XEP_0270(BasePlugin):

    name = 'xep_0270'
    description = 'XEP-0270: XMPP Compliance Suites 2010'
    dependencies = set([
        'xep_0030', 'xep_0115', 'xep_0054', 'xep_0163', 'xep_0045', 'xep_0085'
    ])


register_plugin(XEP_0270)
コード例 #5
0
        session['next'] = self._handle_voting
        return session

    def _handle_limited_voting(self, iq, session):
        voting_session = self.xmpp['xsf_voting'].start_voting(session['from'])
        section = session['ballot_section']

        form = self.xmpp['xep_0004'].stanza.Form()
        form['type'] = 'form'
        form['title'] = 'XSF Election: %s' % section['title']
        form['instructions'] = 'Select the applicants you approve for %s.' % section['title']

        random.shuffle(section['items'])
        items = deque(section['items'])

        for i in range(0, int(section['limit'])):
            form.add_field(var='choice-%s' % i,
                    ftype='list-single',
                    label='Seat %s' % str(i+1))
            for item in items:
                form.field['choice-%s' % i].add_option(value=item['name'])
            items.rotate(1)

        session['payload'] = form
        session['next'] = self._handle_limited_voting
        return session



register_plugin(XSFVotingAdhoc)
コード例 #6
0
ファイル: xep_0106.py プロジェクト: E-Tahta/sleekxmpp
"""
    SleekXMPP: The Sleek XMPP Library
    Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
    This file is part of SleekXMPP.

    See the file LICENSE for copying permission.
"""


from sleekxmpp.plugins import BasePlugin, register_plugin


class XEP_0106(BasePlugin):

    name = 'xep_0106'
    description = 'XEP-0106: JID Escaping'
    dependencies = set(['xep_0030'])

    def session_bind(self, jid):
        self.xmpp['xep_0030'].add_feature(feature='jid\\20escaping')

    def plugin_end(self):
        self.xmpp['xep_0030'].del_feature(feature='jid\\20escaping')


register_plugin(XEP_0106)
コード例 #7
0
ファイル: xep_0242.py プロジェクト: 2M1R/SleekXMPP
"""
    SleekXMPP: The Sleek XMPP Library
    Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
    This file is part of SleekXMPP.

    See the file LICENSE for copying permission.
"""

from sleekxmpp.plugins import BasePlugin, register_plugin


class XEP_0242(BasePlugin):

    name = 'xep_0242'
    description = 'XEP-0242: XMPP Client Compliance 2009'
    dependencies = set(['xep_0030', 'xep_0115', 'xep_0054',
                        'xep_0045', 'xep_0085', 'xep_0016',
                        'xep_0191'])


register_plugin(XEP_0242)
コード例 #8
0
"""
    SleekXMPP: The Sleek XMPP Library
    Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
    This file is part of SleekXMPP.

    See the file LICENSE for copying permission.
"""

from sleekxmpp.plugins import BasePlugin, register_plugin


class XEP_0302(BasePlugin):

    name = 'xep_0302'
    description = 'XEP-0302: XMPP Compliance Suites 2012'
    dependencies = set([
        'xep_0030', 'xep_0115', 'xep_0054', 'xep_0163', 'xep_0045', 'xep_0085',
        'xep_0184', 'xep_0198'
    ])


register_plugin(XEP_0302)
コード例 #9
0
ファイル: xep_0133.py プロジェクト: E-Tahta/sleekxmpp
        'get-online-users-list', 'get-online-users', 'get-active-users',
        'get-idle-userslist', 'announce', 'set-motd', 'edit-motd',
        'delete-motd', 'set-welcome', 'delete-welcome', 'edit-admin',
        'restart', 'shutdown'
    ])

    def get_commands(self, jid=None, **kwargs):
        if jid is None:
            jid = self.xmpp.boundjid.server
        return self.xmpp['xep_0050'].get_commands(jid, **kwargs)


def create_command(name):
    def admin_command(self, jid=None, session=None, ifrom=None, block=False):
        if jid is None:
            jid = self.xmpp.boundjid.server
        self.xmpp['xep_0050'].start_command(
            jid=jid,
            node='http://jabber.org/protocol/admin#%s' % name,
            session=session,
            ifrom=ifrom,
            block=block)

    return admin_command


for cmd in XEP_0133.commands:
    setattr(XEP_0133, cmd.replace('-', '_'), create_command(cmd))

register_plugin(XEP_0133)
コード例 #10
0
ファイル: xep_0138.py プロジェクト: E-Tahta/sleekxmpp
                                   self._handle_compression,
                                   restart=True,
                                   order=self.config.get('order', 5))

    def register_compression_method(self, name, handler):
        self.compression_methods[name] = handler

    def _handle_compression(self, features):
        for method in features['compression']['methods']:
            if method in self.compression_methods:
                log.info('Attempting to use %s compression' % method)
                c = Compress(self.xmpp)
                c['method'] = method
                c.send(now=True)
                return True
        return False

    def _handle_compressed(self, stanza):
        self.xmpp.features.add('compression')
        log.debug('Stream Compressed!')
        compressed_socket = ZlibSocket(self.xmpp.socket)
        self.xmpp.set_socket(compressed_socket)
        raise RestartStream()

    def _handle_failure(self, stanza):
        pass


xep_0138 = XEP_0138
register_plugin(XEP_0138)
コード例 #11
0
ファイル: xep_0033.py プロジェクト: hoangduit/emesene
    def setUri(self, uri):
        if uri:
            del self["jid"]
            del self["node"]
            self.xml.attrib["uri"] = uri
        elif "uri" in self.xml.attrib:
            del self.xml.attrib["uri"]


class XEP_0033(BasePlugin):

    """
    XEP-0033: Extended Stanza Addressing
    """

    name = "xep_0033"
    description = "XEP-0033: Extended Stanza Addressing"
    dependencies = set(["xep_0033"])

    def plugin_init(self):
        self.xep = "0033"

        register_stanza_plugin(Message, Addresses)

        self.xmpp.plugin["xep_0030"].add_feature(Addresses.namespace)


xep_0033 = XEP_0033
register_plugin(XEP_0033)
コード例 #12
0
        form = self.xmpp['xep_0004'].stanza.Form()
        form['type'] = 'form'
        form['title'] = 'Remove XSF Member JID'
        form['instructions'] = 'Enter a JID for an XSF Member'
        form.add_field(var='jid',
                       ftype='jid-single',
                       title='JID',
                       desc='XSF Member JID',
                       required=True)

        session['payload'] = form
        session['has_next'] = False

        def handle_result(form, session):
            jid = JID(form['values']['jid'])

            if jid.bare in self._members:
                self._members.remove(jid)
                self._save_data()
                self.xmpp.event('xsf_jid_removed', jid)

            session['payload'] = None
            session['next'] = None
            return session

        session['next'] = handle_result
        return session


register_plugin(XSFRoster)
コード例 #13
0
ファイル: xep_0256.py プロジェクト: ekini/SleekXMPP
    def _reset_presence_activity(self, e):
        self._initial_presence = set()

    def _initial_presence_activity(self, stanza):
        if isinstance(stanza, Presence):
            use_last_activity = False

            if self.auto_last_activity and  stanza['show'] in ('xa', 'away'):
                use_last_activity = True

            if stanza['from'] not in self._initial_presence:
                self._initial_presence.add(stanza['from'])
                use_last_activity = True

            if use_last_activity:
                plugin = self.xmpp['xep_0012']
                try:
                    result = plugin.api['get_last_activity'](stanza['from'],
                                                             None,
                                                             stanza['to'])
                    seconds = result['last_activity']['seconds']
                except XMPPError:
                    seconds = None

                if seconds is not None:
                    stanza['last_activity']['seconds'] = seconds
        return stanza


register_plugin(XEP_0256)
コード例 #14
0
ファイル: xep_0133.py プロジェクト: 2M1R/SleekXMPP
                    'get-registered-users-list', 'get-disabled-users-list',
                    'get-online-users-list', 'get-online-users',
                    'get-active-users', 'get-idle-userslist', 'announce',
                    'set-motd', 'edit-motd', 'delete-motd', 'set-welcome',
                    'delete-welcome', 'edit-admin', 'restart', 'shutdown'])

    def get_commands(self, jid=None, **kwargs):
        if jid is None:
            jid = self.xmpp.boundjid.server
        return self.xmpp['xep_0050'].get_commands(jid, **kwargs)


def create_command(name):
    def admin_command(self, jid=None, session=None, ifrom=None, block=False):
        if jid is None:
            jid = self.xmpp.boundjid.server
        self.xmpp['xep_0050'].start_command(
                jid=jid,
                node='http://jabber.org/protocol/admin#%s' % name,
                session=session,
                ifrom=ifrom,
                block=block)
    return admin_command


for cmd in XEP_0133.commands:
    setattr(XEP_0133, cmd.replace('-', '_'), create_command(cmd))


register_plugin(XEP_0133)
コード例 #15
0
ファイル: xep_0242.py プロジェクト: E-Tahta/sleekxmpp
"""
    SleekXMPP: The Sleek XMPP Library
    Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
    This file is part of SleekXMPP.

    See the file LICENSE for copying permission.
"""

from sleekxmpp.plugins import BasePlugin, register_plugin


class XEP_0242(BasePlugin):

    name = 'xep_0242'
    description = 'XEP-0242: XMPP Client Compliance 2009'
    dependencies = set([
        'xep_0030', 'xep_0115', 'xep_0054', 'xep_0045', 'xep_0085', 'xep_0016',
        'xep_0191'
    ])


register_plugin(XEP_0242)
コード例 #16
0
ファイル: xep_0270.py プロジェクト: 2M1R/SleekXMPP
"""
    SleekXMPP: The Sleek XMPP Library
    Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
    This file is part of SleekXMPP.

    See the file LICENSE for copying permission.
"""

from sleekxmpp.plugins import BasePlugin, register_plugin


class XEP_0270(BasePlugin):

    name = 'xep_0270'
    description = 'XEP-0270: XMPP Compliance Suites 2010'
    dependencies = set(['xep_0030', 'xep_0115', 'xep_0054',
                        'xep_0163', 'xep_0045', 'xep_0085'])


register_plugin(XEP_0270)
コード例 #17
0
ファイル: voting.py プロジェクト: agnauck/memberbot
        self.redis.hset(
            '%s:session:%s:%s' %
            (self.key_prefix, self.current_ballot, jid.bare), 'votes',
            json.dumps(votes))
        self.redis.hset(
            '%s:session:%s:%s' %
            (self.key_prefix, self.current_ballot, jid.bare), 'fulfilled',
            json.dumps(fulfilled))
        return self.get_session(jid)

    def abstain_vote(self, jid, section, item):
        session = self.get_session(jid)
        votes = session['votes']
        if item in votes[section]:
            del votes[section][item]
        fulfilled = session['fulfilled']
        fulfilled[section] = sum(
            [1 for (name, vote) in votes[section].items() if vote == 'yes'])
        self.redis.hset(
            '%s:session:%s:%s' %
            (self.key_prefix, self.current_ballot, jid.bare), 'votes',
            json.dumps(votes))
        self.redis.hset(
            '%s:session:%s:%s' %
            (self.key_prefix, self.current_ballot, jid.bare), 'fulfilled',
            json.dumps(fulfilled))
        return self.get_session(jid)


register_plugin(XSFVoting)
コード例 #18
0
    def _remove_jid(self, iq, session):
        if iq['from'].bare not in self._admins:
            raise XMPPError('forbidden')

        form = self.xmpp['xep_0004'].stanza.Form()
        form['type'] = 'form'
        form['title'] = 'Remove XSF Member JID'
        form['instructions'] = 'Enter a JID for an XSF Member'
        form.add_field(var='jid', ftype='jid-single', title='JID', desc='XSF Member JID', required=True)

        session['payload'] = form
        session['has_next'] = False

        def handle_result(form, session):
            jid = JID(form['values']['jid'])

            if jid.bare in self._members:
                self._members.remove(jid)
                self._save_data()
                self.xmpp.event('xsf_jid_removed', jid)

            session['payload'] = None
            session['next'] = None
            return session

        session['next'] = handle_result
        return session


register_plugin(XSFRoster)
コード例 #19
0
ファイル: voting.py プロジェクト: joachimlindborg/memberbot
        pre_quorum = self.has_quorum()
        self.redis.sadd('%s:voters:%s' % (self.key_prefix, self.current_ballot), jid)
        if not pre_quorum and self.has_quorum():
            self.xmpp.event('quorum_reached')

        # HACK: Make this just work for member election with the old format
        session = self.get_session(jid)
        membervotes = session['votes']['XSF Membership']
        with open('%s/results/%s/%s.xml' % (self.data_dir, self.current_ballot, jid.bare), 'w+') as result:
            result.write('<?xml version="1.0"?>')
            result.write('<respondent jid="%s">' % jid.bare)
            for i, item in enumerate(self._ballot_data['section']['items']):
                vote = membervotes[item['name']]
                result.write('<!-- %s -->' % item['name'])
                result.write('<answer%s>%s</answer%s>' % (i, vote, i))
            result.write('</respondent>')

    def record_vote(self, jid, section, item, answer):
        session = self.get_session(jid)
        votes = session['votes']
        votes[section][item] = answer
        fulfilled = session['fulfilled']
        fulfilled[section] = sum([1 for (name, vote) in votes[section].items() if vote == 'yes'])
        self.redis.hset('%s:session:%s:%s' % (self.key_prefix, self.current_ballot, jid.bare), 'votes', json.dumps(votes))
        self.redis.hset('%s:session:%s:%s' % (self.key_prefix, self.current_ballot, jid.bare), 'fulfilled', json.dumps(fulfilled))
        return self.get_session(jid)


register_plugin(XSFVoting)
コード例 #20
0
ファイル: xep_0082.py プロジェクト: taoGit/SleekXMPP
    the XMPP.

    Also see <http://www.xmpp.org/extensions/xep-0082.html>.

    Methods:
        date            -- Create a time stamp using the Date profile.
        datetime        -- Create a time stamp using the DateTime profile.
        time            -- Create a time stamp using the Time profile.
        format_date     -- Format an existing date object.
        format_datetime -- Format an existing datetime object.
        format_time     -- Format an existing time object.
        parse           -- Convert a time string into a Python datetime object.
    """

    name = 'xep_0082'
    description = 'XEP-0082: XMPP Date and Time Profiles'
    dependencies = set()

    def plugin_init(self):
        """Start the XEP-0082 plugin."""
        self.date = date
        self.datetime = datetime
        self.time = time
        self.format_date = format_date
        self.format_datetime = format_datetime
        self.format_time = format_time
        self.parse = parse


register_plugin(XEP_0082)
コード例 #21
0
ファイル: xep_0033.py プロジェクト: stlcours/emesene
            del self['delivered']

    def setUri(self, uri):
        if uri:
            del self['jid']
            del self['node']
            self.xml.attrib['uri'] = uri
        elif 'uri' in self.xml.attrib:
            del self.xml.attrib['uri']


class XEP_0033(BasePlugin):
    """
    XEP-0033: Extended Stanza Addressing
    """

    name = 'xep_0033'
    description = 'XEP-0033: Extended Stanza Addressing'
    dependencies = set(['xep_0033'])

    def plugin_init(self):
        self.xep = '0033'

        register_stanza_plugin(Message, Addresses)

        self.xmpp.plugin['xep_0030'].add_feature(Addresses.namespace)


xep_0033 = XEP_0033
register_plugin(XEP_0033)
コード例 #22
0
ファイル: xep_0082.py プロジェクト: 2M1R/SleekXMPP
    the XMPP.

    Also see <http://www.xmpp.org/extensions/xep-0082.html>.

    Methods:
        date            -- Create a time stamp using the Date profile.
        datetime        -- Create a time stamp using the DateTime profile.
        time            -- Create a time stamp using the Time profile.
        format_date     -- Format an existing date object.
        format_datetime -- Format an existing datetime object.
        format_time     -- Format an existing time object.
        parse           -- Convert a time string into a Python datetime object.
    """

    name = 'xep_0082'
    description = 'XEP-0082: XMPP Date and Time Profiles'
    dependencies = set()

    def plugin_init(self):
        """Start the XEP-0082 plugin."""
        self.date = date
        self.datetime = datetime
        self.time = time
        self.format_date = format_date
        self.format_datetime = format_datetime
        self.format_time = format_time
        self.parse = parse


register_plugin(XEP_0082)
コード例 #23
0
ファイル: xep_0302.py プロジェクト: NickBMetaswitch/SleekXMPP
"""
    SleekXMPP: The Sleek XMPP Library
    Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
    This file is part of SleekXMPP.

    See the file LICENSE for copying permission.
"""

from sleekxmpp.plugins import BasePlugin, register_plugin


class XEP_0302(BasePlugin):

    name = "xep_0302"
    description = "XEP-0302: XMPP Compliance Suites 2012"
    dependencies = set(["xep_0030", "xep_0115", "xep_0054", "xep_0163", "xep_0045", "xep_0085", "xep_0184", "xep_0198"])


register_plugin(XEP_0302)
コード例 #24
0
ファイル: chat_voting.py プロジェクト: agnauck/memberbot
        if msg['type'] not in ('normal', 'chat'):
            return
        if not self.xmpp['xsf_roster'].is_member(user):
            log.warn('Unkown user: %s', user)
            return

        if user not in self.sessions:
            self.sessions[user] = VotingSession(self.xmpp, user)
        session = self.sessions[user]
        try:
            session.process(msg['body'], )
        except StopIteration:
            pass


register_plugin(XSFVotingChat)


class VotingSession(object):
    def __init__(self, xmpp, user):
        self.xmpp = xmpp
        self.user = user
        self._session = self._process()
        self._session.next()

    def end(self):
        name = self.xmpp.client_roster[self.user]['name'] or self.user.bare
        self.send('end')
        del self.xmpp['xsf_voting_chat'].sessions[self.user]

    def process(self, user_resp):
コード例 #25
0
ファイル: xep_0045.py プロジェクト: juanrmn/SleekXMPP
        iq['from'] = ifrom
        iq.send()

    def getJoinedRooms(self):
        return self.rooms.keys()

    def getOurJidInRoom(self, roomJid):
        """ Return the jid we're using in a room.
        """
        return "%s/%s" % (roomJid, self.ourNicks[roomJid])

    def getJidProperty(self, room, nick, jidProperty):
        """ Get the property of a nick in a room, such as its 'jid' or 'affiliation'
            If not found, return None.
        """
        if room in self.rooms and nick in self.rooms[room] and jidProperty in self.rooms[room][nick]:
            return self.rooms[room][nick][jidProperty]
        else:
            return None

    def getRoster(self, room):
        """ Get the list of nicks in a room.
        """
        if room not in self.rooms.keys():
            return None
        return self.rooms[room].keys()


xep_0045 = XEP_0045
register_plugin(XEP_0045)
コード例 #26
0
ファイル: xep_0012.py プロジェクト: PADGETS-EU/padgets-repo
            barejid = JID(jid).bare
            if barejid in self.xmpp.roster and ( self.xmpp.roster[barejid]['subscription'] in ('from', 'both') or
                                                 barejid == self.xmpp.boundjid.bare ):
                # We don't know how to calculate it
                iq.reply().error().setPayload(iq['last_activity'].xml)
                iq['error']['code'] = '503'
                iq['error']['type'] = 'cancel'
                iq['error']['condition'] = 'service-unavailable'
                iq.send()
            else:
                iq.reply().error().setPayload(iq['last_activity'].xml)
                iq['error']['code'] = '403'
                iq['error']['type'] = 'auth'
                iq['error']['condition'] = 'forbidden'
                iq.send()

    def get_last_activity(self, jid):
        """Query the LastActivity of jid and return it in seconds"""
        iq = self.xmpp.makeIqGet()
        query = LastActivity()
        iq.append(query.xml)
        iq.attrib['to'] = jid
        iq.attrib['from'] = self.xmpp.boundjid.full
        id = iq.get('id')
        result = iq.send()
        return result['last_activity']['seconds']


xep_0012 = XEP_0012
register_plugin(XEP_0012)