class Blather::Stream::SASL
@private
Constants
- MECHANISMS
- SASL_NS
Public Class Methods
new(stream, succeed, fail)
click to toggle source
Calls superclass method
Blather::Stream::Features::new
# 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
Public Instance Methods
receive_data(stanza)
click to toggle source
# 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
Protected Instance Methods
auth_node(mechanism, content = nil)
click to toggle source
Builds a standard auth node
# File lib/blather/stream/features/sasl.rb, line 88 def auth_node(mechanism, content = nil) node = XMPPNode.new 'auth' node.content = content if content node.namespace = SASL_NS node[:mechanism] = mechanism node end
authenticate_with(method)
click to toggle source
# File lib/blather/stream/features/sasl.rb, line 65 def authenticate_with(method) method = case method when 'digest-md5' then DigestMD5 when 'plain' then Plain when 'anonymous' then Anonymous when nil then fail!(SASLError.import(@node)) else next! end if method.is_a?(Module) extend method authenticate end end
b64(str)
click to toggle source
Base64 Encoder
# File lib/blather/stream/features/sasl.rb, line 82 def b64(str) [str].pack('m').gsub(/\s/,'') end
next!()
click to toggle source
# File lib/blather/stream/features/sasl.rb, line 48 def next! if @jid.node == '' process_anonymous else @idx = @idx ? @idx+1 : 0 authenticate_with @mechanisms[@idx] end end
process_anonymous()
click to toggle source
# File lib/blather/stream/features/sasl.rb, line 57 def process_anonymous if @mechanisms.include?('anonymous') authenticate_with 'anonymous' else fail! BlatherError.new('The server does not support ANONYMOUS login. You must provide a node in the JID') end end