Sha256: b36200836667c48da973ae1f42da19567c50d029765c06b129413ac4f25a2bc2

Contents?: true

Size: 1.55 KB

Versions: 20

Compression:

Stored size: 1.55 KB

Contents

# encoding: UTF-8

module Vines
  class Stream

    # Implements the XMPP protocol for trusted, external component (XEP-0114)
    # streams. This serves connected streams using the jabber:component:accept
    # namespace.
    class Component < Stream
      attr_reader :remote_domain

      def initialize(config)
        super
        @remote_domain = nil
        @stream_id = Kit.uuid
        advance(Start.new(self))
      end

      def max_stanza_size
        config[:component].max_stanza_size
      end

      def ready?
        state.class == Component::Ready
      end

      def stream_type
        :component
      end

      def start(node)
        @remote_domain = node['to']
        send_stream_header
        raise StreamErrors::ImproperAddressing unless valid_address?(@remote_domain)
        raise StreamErrors::HostUnknown unless config.component?(@remote_domain)
        raise StreamErrors::InvalidNamespace unless node.namespaces['xmlns'] == NAMESPACES[:component]
        raise StreamErrors::InvalidNamespace unless node.namespaces['xmlns:stream'] == NAMESPACES[:stream]
      end

      def secret
        password = config.component_password(@remote_domain)
        Digest::SHA1.hexdigest(@stream_id + password)
      end

      private

      def send_stream_header
        attrs = {
          'xmlns' => NAMESPACES[:component],
          'xmlns:stream' => NAMESPACES[:stream],
          'id' => @stream_id,
          'from' => @remote_domain
        }
        write "<stream:stream %s>" % attrs.to_a.map{|k,v| "#{k}='#{v}'"}.join(' ')
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
lygneo-vines-0.1.5 lib/vines/stream/component.rb
lygneo-vines-0.1.1 lib/vines/stream/component.rb
diaspora-vines-0.1.22 lib/vines/stream/component.rb
diaspora-vines-0.1.21 lib/vines/stream/component.rb
diaspora-vines-0.1.2 lib/vines/stream/component.rb
vines-0.4.9 lib/vines/stream/component.rb
vines-0.4.8 lib/vines/stream/component.rb
vines-0.4.7 lib/vines/stream/component.rb
vines-0.4.6 lib/vines/stream/component.rb
vinesmod-0.4.5.2 lib/vines/stream/component.rb
vinesmod-0.4.5 lib/vines/stream/component.rb
vines-0.4.5 lib/vines/stream/component.rb
vines-0.4.4 lib/vines/stream/component.rb
vines-0.4.3 lib/vines/stream/component.rb
vines-0.4.2 lib/vines/stream/component.rb
vines-0.4.1 lib/vines/stream/component.rb
vines-0.4.0 lib/vines/stream/component.rb
vines-0.3.2 lib/vines/stream/component.rb
vines-0.3.1 lib/vines/stream/component.rb
vines-0.3.0 lib/vines/stream/component.rb