Class: Vines::Stream::Client

Inherits:
Vines::Stream
  • Object
show all
Defined in:
lib/vines/stream/client.rb,
lib/vines/stream/client/tls.rb,
lib/vines/stream/client/auth.rb,
lib/vines/stream/client/bind.rb,
lib/vines/stream/client/ready.rb,
lib/vines/stream/client/start.rb,
lib/vines/stream/client/closed.rb,
lib/vines/stream/client/session.rb,
lib/vines/stream/client/auth_restart.rb,
lib/vines/stream/client/bind_restart.rb

Overview

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

Direct Known Subclasses

Http

Defined Under Namespace

Classes: Auth, AuthRestart, Bind, BindRestart, Closed, Ready, Session, Start, TLS

Constant Summary collapse

MECHANISMS =
%w[PLAIN].freeze

Constants inherited from Vines::Stream

ERROR, PAD, STREAM

Instance Attribute Summary

Attributes inherited from Vines::Stream

#config, #domain, #id, #state, #user

Instance Method Summary collapse

Methods inherited from Vines::Stream

#advance, #available_resources, #cert_domain_matches?, #close_connection, #connected_resources, #create_parser, #encrypt, #encrypt?, #error, #interested_resources, #post_init, #receive_data, #reset, #router, #ssl_verify_peer, #storage, #update_user_streams, #vhost, #write

Methods included from Log

#log, set_log_file

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/vines/stream/client.rb', line 10

def initialize(config)
  super
  @session = Client::Session.new(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

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



16
17
18
# File 'lib/vines/stream/client.rb', line 16

def method_missing(name, *args)
  @session.send(name, *args)
end

Instance Method Details

#authentication_mechanismsObject

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



34
35
36
# File 'lib/vines/stream/client.rb', line 34

def authentication_mechanisms
  MECHANISMS
end

#ssl_handshake_completedObject



38
39
40
41
42
# 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) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# 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

#unbindObject



44
45
46
47
# File 'lib/vines/stream/client.rb', line 44

def unbind
  @session.unbind!(self)
  super
end