Class: Blather::FileTransfer

Inherits:
Object
  • Object
show all
Defined in:
lib/blather/file_transfer.rb,
lib/blather/file_transfer/ibb.rb,
lib/blather/file_transfer/s5b.rb

Overview

File Transfer helper Takes care of accepting, declining and offering file transfers through the stream

Defined Under Namespace

Modules: SimpleFileReceiver Classes: Ibb, S5b

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (FileTransfer) initialize(stream, iq = nil)

Create a new FileTransfer



19
20
21
22
23
24
25
# File 'lib/blather/file_transfer.rb', line 19

def initialize(stream, iq = nil)
  @stream = stream
  @allow_s5b = true
  @allow_ibb = true

  @iq = iq
end

Instance Attribute Details

- (Object) allow_ibb

Set this to false if you don't want to use In-Band Bytestreams



7
8
9
# File 'lib/blather/file_transfer.rb', line 7

def allow_ibb
  @allow_ibb
end

- (Object) allow_private_ips

Set this to true if you want SOCKS5 Bytestreams to attempt to use private network addresses



13
14
15
# File 'lib/blather/file_transfer.rb', line 13

def allow_private_ips
  @allow_private_ips
end

- (Object) allow_s5b

Set this to false if you don't want to use SOCKS5 Bytestreams



10
11
12
# File 'lib/blather/file_transfer.rb', line 10

def allow_s5b
  @allow_s5b
end

Instance Method Details

- (Object) accept(handler, *params)

Accept an incoming file-transfer



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/blather/file_transfer.rb', line 31

def accept(handler, *params)
  answer = @iq.reply

  answer.si.feature.x.type = :submit

  supported_methods = @iq.si.feature.x.field("stream-method").options.map(&:value)
  if supported_methods.include?(Stanza::Iq::S5b::NS_S5B) and @allow_s5b
    answer.si.feature.x.fields = {:var => 'stream-method', :value => Stanza::Iq::S5b::NS_S5B}

    @stream.register_handler :s5b_open, :from => @iq.from do |iq|
      transfer = Blather::FileTransfer::S5b.new(@stream, iq)
      transfer.allow_ibb_fallback = true if @allow_ibb
      transfer.allow_private_ips = true if @allow_private_ips
      transfer.accept(handler, *params)
      true
    end

    @stream.write answer
  elsif supported_methods.include?(Stanza::Iq::Ibb::NS_IBB) and @allow_ibb
    answer.si.feature.x.fields = {:var => 'stream-method', :value => Stanza::Iq::Ibb::NS_IBB}

    @stream.register_handler :ibb_open, :from => @iq.from do |iq|
      transfer = Blather::FileTransfer::Ibb.new(@stream, iq)
      transfer.accept(handler, *params)
      true
    end

    @stream.write answer
  else
    reason = XMPPNode.new('no-valid-streams')
    reason.namespace = Blather::Stanza::Iq::Si::NS_SI

    @stream.write StanzaError.new(@iq, 'bad-request', 'cancel', nil, [reason]).to_node
  end
end

- (Object) decline

Decline an incoming file-transfer



68
69
70
71
72
# File 'lib/blather/file_transfer.rb', line 68

def decline
  answer = StanzaError.new(@iq, 'forbidden', 'cancel', 'Offer declined').to_node

  @stream.write answer
end

- (Object) offer

Offer a file to somebody, not implemented yet



75
76
77
# File 'lib/blather/file_transfer.rb', line 75

def offer
  # TODO: implement
end