Class: Blather::Stream::SASL

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

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!, #feature?, from_namespace, register, #succeed!

Constructor Details

#initialize(stream, succeed, fail) ⇒ SASL

Returns a new instance of SASL.



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

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

Instance Method Details

#receive_data(stanza) ⇒ Object



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

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