Sha256: b7502b8d3fb3ff2d0a86674e180cd5072e1101de745372bdca3f21ba33d0e4d9

Contents?: true

Size: 1.31 KB

Versions: 27

Compression:

Stored size: 1.31 KB

Contents

# encoding: UTF-8

module Vines
  class Stanza
    class Iq < Stanza
      register "/iq"

      VALID_TYPES = %w[get set result error].freeze

      VALID_TYPES.each do |type|
        define_method "#{type}?" do
          self['type'] == type
        end
      end

      def process
        if self['id'] && VALID_TYPES.include?(self['type'])
          route_iq or raise StanzaErrors::FeatureNotImplemented.new(@node, 'cancel')
        else
          raise StanzaErrors::BadRequest.new(@node, 'modify')
        end
      end

      def to_result
        doc = Document.new
        doc.create_element('iq',
          'from' => validate_to || stream.domain,
          'id'   => self['id'],
          'to'   => stream.user.jid,
          'type' => 'result')
      end

      private

      # Return false if this IQ stanza is addressed to the server, or a pubsub
      # service hosted here, and must be handled locally. Return true if the
      # stanza must not be handled locally and has been routed to the appropriate
      # component, s2s, or c2s stream.
      def route_iq
        to = validate_to
        return false if to.nil? || stream.config.vhost?(to) || to_pubsub_domain?
        self['from'] = stream.user.jid.to_s
        local? ? broadcast(stream.connected_resources(to)) : route
        true
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
diaspora-vines-0.2.0.develop.4 lib/vines/stanza/iq.rb
diaspora-vines-0.2.0.develop.3 lib/vines/stanza/iq.rb
diaspora-vines-0.2.0.develop.2 lib/vines/stanza/iq.rb
diaspora-vines-0.2.0.develop.1 lib/vines/stanza/iq.rb
diaspora-vines-0.1.28 lib/vines/stanza/iq.rb
lygneo-vines-0.1.5 lib/vines/stanza/iq.rb
lygneo-vines-0.1.1 lib/vines/stanza/iq.rb
diaspora-vines-0.1.27 lib/vines/stanza/iq.rb
diaspora-vines-0.1.26 lib/vines/stanza/iq.rb
diaspora-vines-0.1.25 lib/vines/stanza/iq.rb
diaspora-vines-0.1.24 lib/vines/stanza/iq.rb
vines-0.4.10 lib/vines/stanza/iq.rb
diaspora-vines-0.1.22 lib/vines/stanza/iq.rb
diaspora-vines-0.1.21 lib/vines/stanza/iq.rb
diaspora-vines-0.1.2 lib/vines/stanza/iq.rb
vines-0.4.9 lib/vines/stanza/iq.rb
vines-0.4.8 lib/vines/stanza/iq.rb
vines-0.4.7 lib/vines/stanza/iq.rb
vines-0.4.6 lib/vines/stanza/iq.rb
vinesmod-0.4.5.2 lib/vines/stanza/iq.rb