Esempio n. 1
0
    def plugin_init(self):
        self.xmpp.register_feature('preapproval',
                self._handle_preapproval,
                restart=False,
                order=9001)

        register_stanza_plugin(StreamFeatures, stanza.PreApproval)
Esempio n. 2
0
    def plugin_init(self):
        register_stanza_plugin(Presence, LastActivity)

        self.xmpp.add_filter('out', self._initial_presence_activity)
        self.xmpp.add_event_handler('connected', self._reset_presence_activity)

        self._initial_presence = set()
Esempio n. 3
0
    def plugin_init(self):
        register_stanza_plugin(self.xmpp['xep_0060'].stanza.Item, Bookmarks)

        self.xmpp['xep_0049'].register(Bookmarks)
        self.xmpp['xep_0163'].register_pep('bookmarks', Bookmarks)

        self.xmpp.add_event_handler('session_start', self._autojoin)
Esempio n. 4
0
 def plugin_init(self):
     self._idle_stamps = {}
     register_stanza_plugin(Presence, stanza.Idle)
     self.api.register(self._set_idle, "set_idle", default=True)
     self.api.register(self._get_idle, "get_idle", default=True)
     self.xmpp.register_handler(Callback("Idle Presence", StanzaPath("presence/idle"), self._idle_presence))
     self.xmpp.add_filter("out", self._stamp_idle_presence)
Esempio n. 5
0
    def plugin_init(self):
        """
        Start the XEP-0030 plugin.
        """
        self.xmpp.register_handler(
                Callback('Disco Info',
                         StanzaPath('iq/disco_info'),
                         self._handle_disco_info))

        self.xmpp.register_handler(
                Callback('Disco Items',
                         StanzaPath('iq/disco_items'),
                         self._handle_disco_items))

        register_stanza_plugin(Iq, DiscoInfo)
        register_stanza_plugin(Iq, DiscoItems)

        self.static = StaticDisco(self.xmpp, self)

        self._disco_ops = [
                'get_info', 'set_info', 'set_identities', 'set_features',
                'get_items', 'set_items', 'del_items', 'add_identity',
                'del_identity', 'add_feature', 'del_feature', 'add_item',
                'del_item', 'del_identities', 'del_features', 'cache_info',
                'get_cached_info', 'supports', 'has_identity']

        for op in self._disco_ops:
            self.api.register(getattr(self.static, op), op, default=True)
Esempio n. 6
0
    def plugin_init(self):
        self.xmpp.register_handler(
                Callback('Direct MUC Invitations',
                         StanzaPath('message/groupchat_invite'),
                         self._handle_invite))

        register_stanza_plugin(Message, Invite)
Esempio n. 7
0
    def plugin_init(self):
        self.xmpp.register_feature('rosterver',
                self._handle_rosterver,
                restart=False,
                order=9000)

        register_stanza_plugin(StreamFeatures, stanza.RosterVer)
Esempio n. 8
0
    def testPublishSingle(self):
        """Test publishing a single item."""
        payload = AtomEntry()
        payload['title'] = 'Test'

        register_stanza_plugin(self.xmpp['xep_0060'].stanza.Item, AtomEntry)

        self.xmpp['xep_0060'].publish(
            'pubsub.example.com',
            'somenode',
            id='id42',
            payload=payload)
        self.send("""
          <iq type="set" id="1" to="pubsub.example.com">
            <pubsub xmlns="http://jabber.org/protocol/pubsub">
              <publish node="somenode">
                <item id="id42">
                  <entry xmlns="http://www.w3.org/2005/Atom">
                    <title>Test</title>
                  </entry>
                </item>
              </publish>
            </pubsub>
          </iq>
        """, use_values=False)
Esempio n. 9
0
    def plugin_init(self):
        self.gpg = GPG(gnupghome=self.gpg_home,
                       gpgbinary=self.gpg_binary,
                       use_agent=self.use_agent,
                       keyring=self.keyring)

        self.xmpp.add_filter('out', self._sign_presence)

        self._keyids = {}

        self.api.register(self._set_keyid, 'set_keyid', default=True)
        self.api.register(self._get_keyid, 'get_keyid', default=True)
        self.api.register(self._del_keyid, 'del_keyid', default=True)
        self.api.register(self._get_keyids, 'get_keyids', default=True)

        register_stanza_plugin(Presence, Signed)
        register_stanza_plugin(Message, Encrypted)

        self.xmpp.add_event_handler('unverified_signed_presence',
                self._handle_unverified_signed_presence)

        self.xmpp.register_handler(
                Callback('Signed Presence',
                    StanzaPath('presence/signed'),
                    self._handle_signed_presence))

        self.xmpp.register_handler(
                Callback('Encrypted Message',
                    StanzaPath('message/encrypted'),
                    self._handle_encrypted_message))
Esempio n. 10
0
    def plugin_init(self):
        self.xmpp.namespace_map['http://www.google.com/talk/protocol/auth'] = 'ga'

        register_stanza_plugin(self.xmpp['feature_mechanisms'].stanza.Auth,
                               stanza.GoogleAuth)

        self.xmpp.add_filter('out', self._auth)
Esempio n. 11
0
    def plugin_init(self):
        register_stanza_plugin(Iq, stanza.UserSettings)

        self.xmpp.register_handler(
                Callback('Google Settings',
                    StanzaPath('iq@type=set/google_settings'),
                    self._handle_settings_change))
Esempio n. 12
0
    def plugin_init(self):
        self.xmpp.register_handler(
            Callback('Explicit Message Encryption',
                     StanzaPath('message/eme'),
                     self._handle_eme))

        register_stanza_plugin(Message, Encryption)
Esempio n. 13
0
    def plugin_init(self):
        self.xmpp.register_feature('session',
                self._handle_start_session,
                restart=False,
                order=10001)

        register_stanza_plugin(Iq, stanza.Session)
        register_stanza_plugin(StreamFeatures, stanza.Session)
Esempio n. 14
0
    def plugin_init(self):
        """Start the XEP-0224 plugin."""
        register_stanza_plugin(Message, stanza.Attention)

        self.xmpp.register_handler(
                Callback('Attention',
                    StanzaPath('message/attention'),
                    self._handle_attention))
Esempio n. 15
0
    def plugin_init(self):
        self.xmpp.register_feature('bind',
                self._handle_bind_resource,
                restart=False,
                order=10000)

        register_stanza_plugin(Iq, stanza.Bind)
        register_stanza_plugin(StreamFeatures, stanza.Bind)
Esempio n. 16
0
    def plugin_init(self):
        register_stanza_plugin(Message, stanza.NoSave)
        register_stanza_plugin(Iq, stanza.NoSaveQuery)

        self.xmpp.register_handler(
                Callback('Google Nosave',
                    StanzaPath('iq@type=set/google_nosave'),
                    self._handle_nosave_change))
Esempio n. 17
0
    def plugin_init(self):
        self.xmpp.register_handler(
            Callback('Message Correction',
                     StanzaPath('message/replace'),
                     self._handle_correction))

        register_stanza_plugin(Message, Replace)

        self.xmpp.use_message_ids = True
Esempio n. 18
0
    def _process_command_response(self, iq, session):
        """
        Generate a command reply stanza based on the
        provided session data.

        Arguments:
            iq      -- The command request stanza.
            session -- A dictionary of relevant session data.
        """
        sessionid = session['id']

        payload = session['payload']
        if payload is None:
            payload = []
        if not isinstance(payload, list):
            payload = [payload]

        interfaces = session.get('interfaces', set())
        payload_classes = session.get('payload_classes', set())

        interfaces.update(set([item.plugin_attrib for item in payload]))
        payload_classes.update(set([item.__class__ for item in payload]))

        session['interfaces'] = interfaces
        session['payload_classes'] = payload_classes

        self.sessions[sessionid] = session

        for item in payload:
            register_stanza_plugin(Command, item.__class__, iterable=True)

        iq = iq.reply()
        iq['command']['node'] = session['node']
        iq['command']['sessionid'] = session['id']

        if session['next'] is None:
            iq['command']['actions'] = []
            iq['command']['status'] = 'completed'
        elif session['has_next']:
            actions = ['next']
            if session['allow_complete']:
                actions.append('complete')
            if session['allow_prev']:
                actions.append('prev')
            iq['command']['actions'] = actions
            iq['command']['status'] = 'executing'
        else:
            iq['command']['actions'] = ['complete']
            iq['command']['status'] = 'executing'

        iq['command']['notes'] = session['notes']

        for item in payload:
            iq['command'].append(item)

        iq.send()
Esempio n. 19
0
    def testInitialPayloadCommand(self):
        """Test a command with an initial payload."""

        class TestPayload(ElementBase):
            name = "foo"
            namespace = "test"
            interfaces = {"bar"}
            plugin_attrib = name

        Command = self.xmpp["xep_0050"].stanza.Command
        register_stanza_plugin(Command, TestPayload, iterable=True)

        def handle_command(iq, session):
            initial = session["payload"]
            logging.debug(initial)
            new_payload = TestPayload()
            if initial:
                new_payload["bar"] = "Received: %s" % initial["bar"]
            else:
                new_payload["bar"] = "Failed"

            logging.debug(initial)

            session["payload"] = new_payload
            session["next"] = None
            session["has_next"] = False

            return session

        self.xmpp["xep_0050"].add_command("tester@localhost", "foo", "Do Foo", handle_command)

        self.recv(
            """
          <iq id="11" type="set" to="tester@localhost" from="foo@bar">
            <command xmlns="http://jabber.org/protocol/commands"
                     node="foo"
                     action="execute">
              <foo xmlns="test" bar="baz" />
            </command>
          </iq>
        """
        )

        self.send(
            """
          <iq id="11" type="result" to="foo@bar">
            <command xmlns="http://jabber.org/protocol/commands"
                     node="foo"
                     status="completed"
                     sessionid="_sessionid_">
              <foo xmlns="test" bar="Received: baz" />
            </command>
          </iq>
        """
        )
Esempio n. 20
0
    def plugin_init(self):
        self.xmpp.register_feature('auth',
                self._handle_auth,
                restart=False,
                order=self.order)

        self.xmpp.add_event_handler('legacy_protocol',
                self._handle_legacy_protocol)

        register_stanza_plugin(Iq, stanza.IqAuth)
        register_stanza_plugin(StreamFeatures, stanza.AuthFeature)
Esempio n. 21
0
    def plugin_init(self):
        register_stanza_plugin(Iq, Request)
        register_stanza_plugin(Iq, Slot)
        register_stanza_plugin(Slot, Put)
        register_stanza_plugin(Slot, Get)
        register_stanza_plugin(Put, Header, iterable=True)

        self.xmpp.register_handler(
                Callback('HTTP Upload Request',
                         StanzaPath('iq@type=get/http_upload_request'),
                         self._handle_request))
Esempio n. 22
0
    def plugin_init(self):
        self.xmpp.register_handler(
            Callback('Chat State',
                     StanzaPath('message/chat_state'),
                     self._handle_chat_state))

        register_stanza_plugin(Message, stanza.Active)
        register_stanza_plugin(Message, stanza.Composing)
        register_stanza_plugin(Message, stanza.Gone)
        register_stanza_plugin(Message, stanza.Inactive)
        register_stanza_plugin(Message, stanza.Paused)
Esempio n. 23
0
    def plugin_init(self):
        """Start the XEP-0203 plugin."""

        if not self.local_time:

            def default_local_time(jid):
                return xep_0082.datetime(offset=self.tz_offset)

            self.local_time = default_local_time

        self.xmpp.register_handler(Callback("Entity Time", StanzaPath("iq/entity_time"), self._handle_time_request))
        register_stanza_plugin(Iq, stanza.EntityTime)
Esempio n. 24
0
    def plugin_init(self):
        """
        Start the XEP-0092 plugin.
        """
        if "name" in self.config:
            self.software_name = self.config["name"]

        self.xmpp.register_handler(
            Callback("Software Version", StanzaPath("iq@type=get/software_version"), self._handle_version)
        )

        register_stanza_plugin(Iq, Version)
Esempio n. 25
0
    def _handle_command_complete(self, iq):
        """
        Process a request to finish the execution of command
        and terminate the workflow.

        All data related to the command session will be removed.

        Arguments:
            iq -- The command completion request.
        """
        node = iq['command']['node']
        sessionid = iq['command']['sessionid']
        session = self.sessions.get(sessionid)

        if session:
            handler = session['next']
            interfaces = session['interfaces']
            results = []
            for stanza in iq['command']['substanzas']:
                if stanza.plugin_attrib in interfaces:
                    results.append(stanza)
            if len(results) == 1:
                results = results[0]

            if handler:
                handler(results, session)

            del self.sessions[sessionid]

            payload = session['payload']
            if payload is None:
                payload = []
            if not isinstance(payload, list):
                payload = [payload]

            for item in payload:
                register_stanza_plugin(Command, item.__class__, iterable=True)

            iq = iq.reply()

            iq['command']['node'] = node
            iq['command']['sessionid'] = sessionid
            iq['command']['actions'] = []
            iq['command']['status'] = 'completed'
            iq['command']['notes'] = session['notes']

            for item in payload:
                iq['command'].append(item)

            iq.send()
        else:
            raise XMPPError('item-not-found')
Esempio n. 26
0
    def plugin_init(self):
        register_stanza_plugin(Iq, Confirm)
        register_stanza_plugin(Message, Confirm)

        self.xmpp.register_handler(
            Callback('Confirm',
                 StanzaPath('iq@type=get/confirm'),
                 self._handle_iq_confirm))

        self.xmpp.register_handler(
            Callback('Confirm',
                 StanzaPath('message/confirm'),
                 self._handle_message_confirm))
Esempio n. 27
0
    def plugin_init(self):
        """
        Start the XEP-0092 plugin.
        """
        if 'name' in self.config:
            self.software_name = self.config['name']

        self.xmpp.register_handler(
                Callback('Software Version',
                         StanzaPath('iq@type=get/software_version'),
                         self._handle_version))

        register_stanza_plugin(Iq, Version)
Esempio n. 28
0
    def plugin_init(self):
        """Start the XEP-0352 plugin."""

        self.enabled = False

        register_stanza_plugin(StreamFeatures, ClientStateIndication)
        self.xmpp.register_stanza(stanza.Active)
        self.xmpp.register_stanza(stanza.Inactive)

        self.xmpp.register_feature('csi',
                self._handle_csi_feature,
                restart=False,
                order=self.order)
Esempio n. 29
0
    def plugin_init(self):
        self.hashes = {'sha-1': hashlib.sha1,
                       'sha1': hashlib.sha1,
                       'md5': hashlib.md5}

        if self.caps_node is None:
            self.caps_node = 'http://slixmpp.com/ver/%s' % __version__

        if self.cache is None:
            self.cache = MemoryCache()

        register_stanza_plugin(Presence, stanza.Capabilities)
        register_stanza_plugin(StreamFeatures, stanza.Capabilities)

        self._disco_ops = ['cache_caps',
                           'get_caps',
                           'assign_verstring',
                           'get_verstring',
                           'supports',
                           'has_identity']

        self.xmpp.register_handler(
                Callback('Entity Capabilites',
                         StanzaPath('presence/caps'),
                         self._handle_caps))

        self.xmpp.add_filter('out', self._filter_add_caps)

        self.xmpp.add_event_handler('entity_caps', self._process_caps)

        if not self.xmpp.is_component:
            self.xmpp.register_feature('caps',
                    self._handle_caps_feature,
                    restart=False,
                    order=10010)

        disco = self.xmpp['xep_0030']
        self.static = StaticCaps(self.xmpp, disco.static)

        for op in self._disco_ops:
            self.api.register(getattr(self.static, op), op, default=True)

        for op in ('supports', 'has_identity'):
            self.xmpp['xep_0030'].api.register(getattr(self.static, op), op)

        self._run_node_handler = disco._run_node_handler

        disco.cache_caps = self.cache_caps
        disco.update_caps = self.update_caps
        disco.assign_verstring = self.assign_verstring
        disco.get_verstring = self.get_verstring
Esempio n. 30
0
 def plugin_init(self):
     self._idle_stamps = {}
     register_stanza_plugin(Presence, stanza.Idle)
     self.api.register(self._set_idle,
             'set_idle',
             default=True)
     self.api.register(self._get_idle,
             'get_idle',
             default=True)
     self.xmpp.register_handler(
             Callback('Idle Presence',
                 StanzaPath('presence/idle'),
                 self._idle_presence))
     self.xmpp.add_filter('out', self._stamp_idle_presence)
Esempio n. 31
0
 def plugin_init(self):
     """
     Start the XEP-0059 plugin.
     """
     register_stanza_plugin(self.xmpp['xep_0030'].stanza.DiscoItems,
                            self.stanza.Set)
Esempio n. 32
0
 def setUp(self):
     register_stanza_plugin(Message, stanza.Reactions)
     register_stanza_plugin(stanza.Reactions, stanza.Reaction)
Esempio n. 33
0
        result = []
        senders = self.xml.findall('{%s}senders/{%s}sender' %
                                   (self.namespace, self.namespace))

        for sender in senders:
            result.append(MailSender(xml=sender))

        return result


class MailSender(ElementBase):
    namespace = 'google:mail:notify'
    name = 'sender'
    plugin_attrib = name
    interfaces = set(['address', 'name', 'originator', 'unread'])

    def get_originator(self):
        return self.xml.attrib.get('originator', '0') == '1'

    def get_unread(self):
        return self.xml.attrib.get('unread', '0') == '1'


class NewMail(ElementBase):
    namespace = 'google:mail:notify'
    name = 'new-mail'
    plugin_attrib = 'gmail_notification'


register_stanza_plugin(MailBox, MailThread, iterable=True)
Esempio n. 34
0
 def plugin_init(self):
     register_stanza_plugin(Message, Store)
     register_stanza_plugin(Message, NoStore)
     register_stanza_plugin(Message, NoPermanentStore)
     register_stanza_plugin(Message, NoCopy)
Esempio n. 35
0
def register_plugins():
    register_stanza_plugin(Iq, ClientJoin)
    register_stanza_plugin(ClientJoin, Join)

    register_stanza_plugin(Iq, ClientLeave)
    register_stanza_plugin(ClientLeave, Leave)

    register_stanza_plugin(Roster, Annotate)
    register_stanza_plugin(RosterItem, Channel)
Esempio n. 36
0
    def __init__(self, jid, password):
        ''' x   '''
        slixmpp.ClientXMPP.__init__(self, jid, password)

        import os, binascii
        self.requested_jid.resource = binascii.b2a_hex(os.urandom(4))

        # register pluginss
        self.register_plugin('xep_0030')  # RPC
        self.register_plugin('xep_0060')  # PubSub
        self.register_plugin('xep_0199', {
            'keepalive': True,
            'frequency': 60
        })  # ping

        register_stanza_plugin(Iq, RPCQuery)
        register_stanza_plugin(RPCQuery, MethodCall)
        register_stanza_plugin(RPCQuery, MethodResponse)

        register_stanza_plugin(Message, Event)
        register_stanza_plugin(Event, EventItems)
        register_stanza_plugin(EventItems, EventItem, iterable=True)
        register_stanza_plugin(EventItem, ItemUpdate)

        # handle session_start and message events
        self.add_event_handler("session_start", self.start)
        self.add_event_handler("roster_update", self.roster_callback)
        self.add_event_handler("pubsub_publish", self.pub_sub_callback)
        self.add_event_handler("failed_auth", self.failed_auth)
Esempio n. 37
0
    def __init__(self, jid, password, host, port, fahversion, iterations=None, salt=None, reconnect=True):
        """ x   """
        slixmpp.ClientXMPP.__init__(self, jid, password, sasl_mech='SCRAM-SHA-1')

        self.fahversion = fahversion
        self.x_jid = jid
        self._host = host
        self._port = port
        self.reconnect = reconnect

        LOG.info(' version: %s', self.fahversion)

        self.password = password
        self.iterations = iterations
        self.salt = salt

        if version.parse(self.fahversion) >= version.parse("2.3.0"):
            self.saslhandler = SaslHandler(self, self.x_jid, self.password, self.iterations, self.salt)

        import os
        import binascii
        self.requested_jid.resource = binascii.b2a_hex(os.urandom(4))

        # handle session_start and message events
        self.add_event_handler("session_start", self.start)
        self.add_event_handler("roster_update", self.roster_callback)
        self.add_event_handler("pubsub_publish", self.pub_sub_callback)
        self.add_event_handler("failed_auth", self.failed_auth)
        self.add_event_handler("disconnected", self._disconnected)
        
        # register plugins
        self.register_plugin('xep_0030')  # RPC
        self.register_plugin('xep_0060')  # PubSub
        self.register_plugin('xep_0199', {'keepalive': True, 'frequency': 60})  # ping

        
        register_stanza_plugin(Iq, RPCQuery)
        register_stanza_plugin(RPCQuery, MethodCall)
        register_stanza_plugin(RPCQuery, MethodResponse)

        register_stanza_plugin(Message, Event)
        register_stanza_plugin(Event, EventItems)
        register_stanza_plugin(EventItems, EventItem, iterable=True)
        register_stanza_plugin(EventItem, ItemUpdate)
        register_stanza_plugin(EventItem, ItemUpdateEncrypted)
Esempio n. 38
0
        else:
            self._set_attr('action', value)

    def set_presence_in(self, value):
        keep = True if value else False
        self._set_sub_text('presence-in', '', keep=keep)

    def get_presence_in(self):
        pres = self.xml.find('{%s}presence-in' % self.namespace)
        return pres is not None

    def del_presence_in(self):
        self._del_sub('{%s}presence-in' % self.namespace)

    def set_presence_out(self, value):
        keep = True if value else False
        self._set_sub_text('presence-in', '', keep=keep)

    def get_presence_out(self):
        pres = self.xml.find('{%s}presence-in' % self.namespace)
        return pres is not None

    def del_presence_out(self):
        self._del_sub('{%s}presence-in' % self.namespace)


register_stanza_plugin(Privacy, Active)
register_stanza_plugin(Privacy, Default)
register_stanza_plugin(Privacy, List, iterable=True)
register_stanza_plugin(List, Item, iterable=True)
Esempio n. 39
0
    interfaces = {'name', 'size', 'date', 'hash', 'desc'}
    sub_interfaces = {'desc'}

    def set_size(self, value):
        self._set_attr('size', str(value))

    def get_date(self):
        timestamp = self._get_attr('date')
        return xep_0082.parse(timestamp)

    def set_date(self, value):
        if isinstance(value, dt.datetime):
            value = xep_0082.format_datetime(value)
        self._set_attr('date', value)


class Range(ElementBase):
    name = 'range'
    namespace = 'http://jabber.org/protocol/si/profile/file-transfer'
    plugin_attrib = 'range'
    interfaces = {'length', 'offset'}

    def set_length(self, value):
        self._set_attr('length', str(value))

    def set_offset(self, value):
        self._set_attr('offset', str(value))


register_stanza_plugin(File, Range)
Esempio n. 40
0
"""
    Slixmpp: The Slick XMPP Library
    Copyright (C) 2010  Nathanael C. Fritz
    This file is part of Slixmpp.

    See the file LICENSE for copying permission.
"""

from slixmpp.stanza import Message
from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.plugins.xep_0071 import XHTML_IM as HTMLIM

register_stanza_plugin(Message, HTMLIM)
Esempio n. 41
0
    def get_expiry(self):
        expiry = self._get_attr('expiry')
        if expiry.lower() == 'presence':
            return expiry
        return xep_0082.parse(expiry)

    def set_expiry(self, value):
        if isinstance(value, dt.datetime):
            value = xep_0082.format_datetime(value)
        self._set_attr('expiry', value)

    def set_jid(self, value):
        self._set_attr('jid', str(value))

    def get_jid(self):
        return JID(self._get_attr('jid'))


register_stanza_plugin(Message, Event)
register_stanza_plugin(Event, EventCollection)
register_stanza_plugin(Event, EventConfiguration)
register_stanza_plugin(Event, EventPurge)
register_stanza_plugin(Event, EventDelete)
register_stanza_plugin(Event, EventItems)
register_stanza_plugin(Event, EventSubscription)
register_stanza_plugin(EventCollection, EventAssociate)
register_stanza_plugin(EventCollection, EventDisassociate)
register_stanza_plugin(EventConfiguration, Form)
register_stanza_plugin(EventItems, EventItem, iterable=True)
register_stanza_plugin(EventItems, EventRetract, iterable=True)
Esempio n. 42
0
    """ Cancel element used to signal that a request shall be cancelled """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'cancel'
    plugin_attrib = name
    interfaces = set(['seqnr'])


class Cancelled(ElementBase):
    """ Cancelled element used to signal that cancellation is confirmed """
    namespace = 'urn:xmpp:iot:sensordata'
    name = 'cancelled'
    plugin_attrib = name
    interfaces = set(['seqnr'])


register_stanza_plugin(Iq, Request)
register_stanza_plugin(Request, RequestNode, iterable=True)
register_stanza_plugin(Request, RequestField, iterable=True)

register_stanza_plugin(Iq, Accepted)
register_stanza_plugin(Message, Failure)
register_stanza_plugin(Failure, Error)

register_stanza_plugin(Iq, Rejected)

register_stanza_plugin(Message, Fields)
register_stanza_plugin(Fields, FieldsNode, iterable=True)
register_stanza_plugin(FieldsNode, Timestamp, iterable=True)
register_stanza_plugin(Timestamp, Field, iterable=True)
register_stanza_plugin(Timestamp, DataNumeric, iterable=True)
register_stanza_plugin(Timestamp, DataString, iterable=True)
Esempio n. 43
0
from slixmpp import Callback, JID
from slixmpp.exceptions import XMPPError
from slixmpp.stanza import Iq, roster as roster_stanza
from slixmpp.xmlstream import register_stanza_plugin
from .matcher import ServerStanzaPath

register_stanza_plugin(Iq, roster_stanza.Roster)


class Roster(object):
    def __init__(self, stream):
        self.stream = stream
        self.interested = False
        self.cached = None
        self.delay_pushes = 0
        self.delayed_pushes = []

        stream.register_plugin('feature_preapproval')
        # TBD: should we try to support roster versioning?
        stream.register_handler(
            Callback('Roster', ServerStanzaPath('iq/roster'),
                     self._handle_roster))

    def _handle_roster(self, iq):
        iq['from'] = self.stream.boundjid
        type = iq['type']
        if type == 'get':
            self.interested = True
            self.stream.loop.create_task(self._get_roster(iq))
        elif type == 'set':
            self.stream.loop.create_task(self._set_roster(iq))
Esempio n. 44
0
    def set_publish_options(self, value):
        if value is None:
            self.del_publish_options()
        else:
            self.xml.append(value.getXML())
        return self

    def del_publish_options(self):
        config = self.xml.find('{jabber:x:data}x')
        if config is not None:
            self.xml.remove(config)
        self.parent().xml.remove(self.xml)


register_stanza_plugin(Iq, Pubsub)
register_stanza_plugin(Pubsub, Affiliations)
register_stanza_plugin(Pubsub, Configure)
register_stanza_plugin(Pubsub, Create)
register_stanza_plugin(Pubsub, Default)
register_stanza_plugin(Pubsub, Items)
register_stanza_plugin(Pubsub, Options)
register_stanza_plugin(Pubsub, Publish)
register_stanza_plugin(Pubsub, PublishOptions)
register_stanza_plugin(Pubsub, Retract)
register_stanza_plugin(Pubsub, Subscribe)
register_stanza_plugin(Pubsub, Subscription)
register_stanza_plugin(Pubsub, Subscriptions)
register_stanza_plugin(Pubsub, Unsubscribe)
register_stanza_plugin(Affiliations, Affiliation, iterable=True)
register_stanza_plugin(Configure, xep_0004.Form)
Esempio n. 45
0
    def plugin_init(self):
        register_stanza_plugin(self.xmpp['xep_0095'].stanza.SI, File)

        self.xmpp['xep_0095'].register_profile(File.namespace, self)
Esempio n. 46
0
 def plugin_init(self):
     """Start the XEP-0203 plugin."""
     register_stanza_plugin(Message, stanza.Delay)
     register_stanza_plugin(Presence, stanza.Delay)
Esempio n. 47
0
 def plugin_init(self) -> None:
     # XXX: This should be MucMessage. Someday..
     register_stanza_plugin(Message, OccupantId)
Esempio n. 48
0
 def plugin_init(self):
     register_stanza_plugin(Iq, stanza.Preferences)
Esempio n. 49
0
 def plugin_init(self):
     register_stanza_plugin(FormField, Media)
Esempio n. 50
0
    def plugin_init(self):
        register_stanza_plugin(Message, stanza.AMP)
        register_stanza_plugin(Error, stanza.InvalidRules)
        register_stanza_plugin(Error, stanza.UnsupportedConditions)
        register_stanza_plugin(Error, stanza.UnsupportedActions)
        register_stanza_plugin(Error, stanza.FailedRules)

        self.xmpp.register_handler(
            Callback(
                'AMP Response',
                MatchMany([
                    StanzaPath('message/error/failed_rules'),
                    StanzaPath('message/amp')
                ]), self._handle_amp_response))

        if not self.xmpp.is_component:
            self.xmpp.register_feature('amp',
                                       self._handle_amp_feature,
                                       restart=False,
                                       order=9000)
            register_stanza_plugin(StreamFeatures, stanza.AMPFeature)
Esempio n. 51
0
    name = 'media'
    namespace = 'urn:xmpp:media-element'
    plugin_attrib = 'media'
    interfaces = set(['height', 'width', 'alt'])

    def add_uri(self, value, itype):
        uri = URI()
        uri['value'] = value
        uri['type'] = itype
        self.append(uri)


class URI(ElementBase):
    name = 'uri'
    namespace = 'urn:xmpp:media-element'
    plugin_attrib = 'uri'
    plugin_multi_attrib = 'uris'
    interfaces = set(['type', 'value'])

    def get_value(self):
        return self.xml.text

    def set_value(self, value):
        self.xml.text = value

    def del_value(self):
        sel.xml.text = ''


register_stanza_plugin(Media, URI, iterable=True)
Esempio n. 52
0
 def plugin_init(self):
     register_stanza_plugin(Message, Addresses)
     register_stanza_plugin(Presence, Addresses)
Esempio n. 53
0
 def plugin_init(self):
     register_stanza_plugin(Block, stanza.Report)
     register_stanza_plugin(stanza.Report, stanza.Text)
Esempio n. 54
0
 def plugin_init(self):
     register_stanza_plugin(Message, SecurityLabel)
     register_stanza_plugin(Iq, Catalog)
Esempio n. 55
0
    def __init__(self, jid, password):
        slixmpp.ClientXMPP.__init__(self, jid, password)

        # register plugins
        self.register_plugin('xep_0030')  # RPC
        self.register_plugin('xep_0060')  # PubSub
        self.register_plugin('xep_0199', {'keepalive': True, 'frequency': 60})

        register_stanza_plugin(Iq, RPCQuery)
        register_stanza_plugin(RPCQuery, MethodCall)
        register_stanza_plugin(RPCQuery, MethodResponse)

        register_stanza_plugin(Message, Event)
        register_stanza_plugin(Event, EventItems)
        register_stanza_plugin(EventItems, EventItem, iterable=True)
        register_stanza_plugin(EventItem, ItemUpdate)

        # handle session_start and message events
        self.add_event_handler("session_start", self.start)
        self.add_event_handler("message", self.message)
        self.add_event_handler("roster_update_complete", self.roster_callback)
        self.add_event_handler("pubsub_publish", self.pub_sub_callback)
Esempio n. 56
0
 def plugin_init(self):
     register_stanza_plugin(Iq, stanza.Offline)
     register_stanza_plugin(Message, stanza.Offline)
Esempio n. 57
0
def register_plugins():
    register_stanza_plugin(Iq, ClientJoin)
    register_stanza_plugin(ClientJoin, Join)

    register_stanza_plugin(Iq, ClientLeave)
    register_stanza_plugin(ClientLeave, Leave)
Esempio n. 58
0
    def plugin_init(self):
        """Start the XEP-0198 plugin."""

        # Only enable stream management for non-components,
        # since components do not yet perform feature negotiation.
        if self.xmpp.is_component:
            return

        self.window_counter = self.window
        self.window_counter_lock = threading.Lock()

        self.enabled = threading.Event()
        self.unacked_queue = collections.deque()

        self.seq_lock = threading.Lock()
        self.handled_lock = threading.Lock()
        self.ack_lock = threading.Lock()

        register_stanza_plugin(StreamFeatures, stanza.StreamManagement)
        self.xmpp.register_stanza(stanza.Enable)
        self.xmpp.register_stanza(stanza.Enabled)
        self.xmpp.register_stanza(stanza.Resume)
        self.xmpp.register_stanza(stanza.Resumed)
        self.xmpp.register_stanza(stanza.Ack)
        self.xmpp.register_stanza(stanza.RequestAck)

        # Only end the session when a </stream> element is sent,
        # not just because the connection has died.
        self.xmpp.end_session_on_disconnect = False

        # Register the feature twice because it may be ordered two
        # different ways: enabling after binding and resumption
        # before binding.
        self.xmpp.register_feature('sm',
                                   self._handle_sm_feature,
                                   restart=True,
                                   order=self.order)
        self.xmpp.register_feature('sm',
                                   self._handle_sm_feature,
                                   restart=True,
                                   order=self.resume_order)

        self.xmpp.register_handler(
            Callback('Stream Management Enabled',
                     MatchXPath(stanza.Enabled.tag_name()),
                     self._handle_enabled,
                     instream=True))

        self.xmpp.register_handler(
            Callback('Stream Management Resumed',
                     MatchXPath(stanza.Resumed.tag_name()),
                     self._handle_resumed,
                     instream=True))

        self.xmpp.register_handler(
            Callback('Stream Management Failed',
                     MatchXPath(stanza.Failed.tag_name()),
                     self._handle_failed,
                     instream=True))

        self.xmpp.register_handler(
            Callback('Stream Management Ack',
                     MatchXPath(stanza.Ack.tag_name()),
                     self._handle_ack,
                     instream=True))

        self.xmpp.register_handler(
            Callback('Stream Management Request Ack',
                     MatchXPath(stanza.RequestAck.tag_name()),
                     self._handle_request_ack,
                     instream=True))

        self.xmpp.add_filter('in', self._handle_incoming)
        self.xmpp.add_filter('out_sync', self._handle_outgoing)

        self.xmpp.add_event_handler('session_end', self.session_end)
Esempio n. 59
0
 def plugin_init(self):
     register_stanza_plugin(Iq, Certs)
     register_stanza_plugin(Iq, AppendCert)
     register_stanza_plugin(Iq, DisableCert)
     register_stanza_plugin(Iq, RevokeCert)
Esempio n. 60
0
 def plugin_init(self):
     register_stanza_plugin(Iq, IPCheck)