Class: Blather::Stream::SASL

Inherits:
Features show all
Defined in:
lib/blather/stream/features/sasl.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Anonymous, DigestMD5, Plain Classes: UnknownMechanism

Constant Summary collapse

MECHANISMS =
%w[
  digest-md5
  plain
  anonymous
].freeze
SASL_NS =
'urn:ietf:params:xml:ns:xmpp-sasl'.freeze

Instance Method Summary collapse

Methods inherited from Features

#fail!, from_namespace, register, #succeed!

Constructor Details

#initialize(stream, succeed, fail) ⇒ SASL

Returns a new instance of SASL.



18
19
20
21
22
23
# File 'lib/blather/stream/features/sasl.rb', line 18

def initialize(stream, succeed, fail)
  super
  @jid = @stream.jid
  @pass = @stream.password
  @mechanisms = []
end

Instance Method Details

#receive_data(stanza) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/blather/stream/features/sasl.rb', line 25

def receive_data(stanza)
  @node = stanza
  case stanza.element_name
  when 'mechanisms'
    available_mechanisms = stanza.children.map { |m| m.content.downcase }
    @mechanisms = MECHANISMS.select { |m| available_mechanisms.include? m }
    next!
  when 'failure'
    next!
  when 'success'
    @stream.start
  else
    if self.respond_to?(stanza.element_name)
      self.__send__(stanza.element_name)
    else
      fail! UnknownResponse.new(stanza)
    end
  end
end