class Vines::Stream::Client

Implements the XMPP protocol for client-to-server (c2s) streams. This serves connected streams using the jabber:client namespace.

Constants

MECHANISMS

Public Class Methods

new(config) click to toggle source
Calls superclass method Vines::Stream::new
# File lib/vines/stream/client.rb, line 10
def initialize(config)
  super
  @session = Client::Session.new(self)
end

Public Instance Methods

authentication_mechanisms() click to toggle source

Return an array of allowed authentication mechanisms advertised as client stream features.

# File lib/vines/stream/client.rb, line 34
def authentication_mechanisms
  MECHANISMS
end
method_missing(name, *args) click to toggle source

Delegate behavior to the session that's storing our stream state.

# File lib/vines/stream/client.rb, line 16
def method_missing(name, *args)
  @session.send(name, *args)
end
ssl_handshake_completed() click to toggle source
# File lib/vines/stream/client.rb, line 38
def ssl_handshake_completed
  if get_peer_cert
    close_connection unless cert_domain_matches?(@session.domain)
  end
end
start(node) click to toggle source
# File lib/vines/stream/client.rb, line 49
def start(node)
  to, from = %w[to from].map {|a| node[a] }
  @session.domain = to unless @session.domain
  send_stream_header(from)
  raise StreamErrors::NotAuthorized if domain_change?(to)
  raise StreamErrors::UnsupportedVersion unless node['version'] == '1.0'
  raise StreamErrors::ImproperAddressing unless valid_address?(@session.domain)
  raise StreamErrors::HostUnknown unless config.vhost?(@session.domain)
  raise StreamErrors::InvalidNamespace unless node.namespaces['xmlns'] == NAMESPACES[:client]
  raise StreamErrors::InvalidNamespace unless node.namespaces['xmlns:stream'] == NAMESPACES[:stream]
end
unbind() click to toggle source
Calls superclass method Vines::Stream#unbind
# File lib/vines/stream/client.rb, line 44
def unbind
  @session.unbind!(self)
  super
end

Private Instance Methods

domain_change?(to) click to toggle source

The to domain address set on the initial stream header must not change during stream restarts. This prevents a user from authenticating in one domain, then using a stream in a different domain.

# File lib/vines/stream/client.rb, line 66
def domain_change?(to)
  to != @session.domain
end
send_stream_header(to) click to toggle source
# File lib/vines/stream/client.rb, line 70
def send_stream_header(to)
  attrs = {
    'xmlns' => NAMESPACES[:client],
    'xmlns:stream' => NAMESPACES[:stream],
    'xml:lang' => 'en',
    'id' => Kit.uuid,
    'from' => @session.domain,
    'version' => '1.0'
  }
  attrs['to'] = to if to
  write "<stream:stream %s>" % attrs.to_a.map{|k,v| "#{k}='#{v}'"}.join(' ')
end