summaryrefslogtreecommitdiff
path: root/sleekxmpp/features/sasl_anonymous.py
blob: 469d9d192eeda2e6b317c5ec4dbfdcb42ac23b5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import base64
import sys
import logging

from sleekxmpp.stanza.stream import sasl
from sleekxmpp.plugins.base import base_plugin


log = logging.getLogger(__name__)


class sasl_anonymous(base_plugin):

    def plugin_init(self):
        self.name = 'SASL ANONYMOUS'
        self.rfc = '6120'
        self.description = 'SASL ANONYMOUS Mechanism'

        self.xmpp.register_sasl_mechanism('ANONYMOUS',
                self._handle_anonymous,
                priority=self.config.get('priority', 0))

    def _handle_anonymous(self):
        if self.xmpp.boundjid.user:
            return False

        resp = sasl.Auth(self.xmpp)
        resp['mechanism'] = 'ANONYMOUS'
        resp.send(now=True)

        return True