Class: Blather::FileTransfer
- Inherits:
-
Object
- Object
- Blather::FileTransfer
- 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
-
#allow_ibb ⇒ Object
Set this to false if you don’t want to use In-Band Bytestreams.
-
#allow_private_ips ⇒ Object
Set this to true if you want SOCKS5 Bytestreams to attempt to use private network addresses.
-
#allow_s5b ⇒ Object
Set this to false if you don’t want to use SOCKS5 Bytestreams.
Instance Method Summary collapse
-
#accept(handler, *params) ⇒ Object
Accept an incoming file-transfer.
-
#decline ⇒ Object
Decline an incoming file-transfer.
-
#initialize(stream, iq = nil) ⇒ FileTransfer
constructor
Create a new FileTransfer.
-
#offer ⇒ Object
Offer a file to somebody, not implemented yet.
Constructor Details
#initialize(stream, iq = nil) ⇒ FileTransfer
Create a new FileTransfer
19 20 21 22 23 24 25 26 27 |
# File 'lib/blather/file_transfer.rb', line 19 def initialize(stream, iq = nil) @stream = stream @allow_s5b = true @allow_ibb = true Blather.logger.debug "File transfers on the local network are ignored by default. Set #allow_private_ips = true if you need local network file transfers." @iq = iq end |
Instance Attribute Details
#allow_ibb ⇒ Object
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 |
#allow_private_ips ⇒ Object
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 |
#allow_s5b ⇒ Object
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
#accept(handler, *params) ⇒ Object
Accept an incoming file-transfer
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 66 67 |
# File 'lib/blather/file_transfer.rb', line 33 def accept(handler, *params) answer = @iq.reply answer.si.feature.x.type = :submit supported_methods = @iq.si.feature.x.field("stream-method")..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 EM.next_tick { 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) EM.next_tick { 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 |
#decline ⇒ Object
Decline an incoming file-transfer
70 71 72 73 74 |
# File 'lib/blather/file_transfer.rb', line 70 def decline answer = StanzaError.new(@iq, 'forbidden', 'cancel', 'Offer declined').to_node @stream.write answer end |
#offer ⇒ Object
Offer a file to somebody, not implemented yet
77 78 79 |
# File 'lib/blather/file_transfer.rb', line 77 def offer # TODO: implement end |