Class: Blather::FileTransfer::Ibb
- Inherits:
-
Object
- Object
- Blather::FileTransfer::Ibb
- Defined in:
- lib/blather/file_transfer/ibb.rb
Overview
In-Band Bytestreams Transfer helper Takes care of accepting, declining and offering file transfers through the stream
Instance Method Summary collapse
-
#accept(handler, *params) ⇒ Object
Accept an incoming file-transfer.
-
#decline ⇒ Object
Decline an incoming file-transfer.
-
#initialize(stream, iq) ⇒ Ibb
constructor
A new instance of Ibb.
-
#offer ⇒ Object
Offer a file to somebody, not implemented yet.
Constructor Details
#initialize(stream, iq) ⇒ Ibb
Returns a new instance of Ibb.
8 9 10 11 12 |
# File 'lib/blather/file_transfer/ibb.rb', line 8 def initialize(stream, iq) @stream = stream @iq = iq @seq = 0 end |
Instance Method Details
#accept(handler, *params) ⇒ Object
Accept an incoming file-transfer
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/blather/file_transfer/ibb.rb', line 18 def accept(handler, *params) @io_read, @io_write = IO.pipe EM::attach @io_read, handler, *params @stream.register_handler :ibb_data, :from => @iq.from, :sid => @iq.sid do |iq| if iq.data['seq'] == @seq.to_s begin @io_write << Base64.decode64(iq.data.content) @stream.write iq.reply @seq += 1 @seq = 0 if @seq > 65535 rescue Errno::EPIPE => e @stream.write StanzaError.new(iq, 'not-acceptable', :cancel).to_node end else @stream.write StanzaError.new(iq, 'unexpected-request', :wait).to_node end true end @stream.register_handler :ibb_close, :from => @iq.from, :sid => @iq.sid do |iq| @stream.write iq.reply @stream.clear_handlers :ibb_data, :from => @iq.from, :sid => @iq.sid @stream.clear_handlers :ibb_close, :from => @iq.from, :sid => @iq.sid @io_write.close true end @stream.clear_handlers :ibb_open, :from => @iq.from @stream.clear_handlers :ibb_open, :from => @iq.from, :sid => @iq.sid @stream.write @iq.reply end |
#decline ⇒ Object
Decline an incoming file-transfer
55 56 57 58 59 60 |
# File 'lib/blather/file_transfer/ibb.rb', line 55 def decline @stream.clear_handlers :ibb_open, :from => @iq.from @stream.clear_handlers :ibb_data, :from => @iq.from, :sid => @iq.sid @stream.clear_handlers :ibb_close, :from => @iq.from, :sid => @iq.sid @stream.write StanzaError.new(@iq, 'not-acceptable', :cancel).to_node end |
#offer ⇒ Object
Offer a file to somebody, not implemented yet
63 64 65 |
# File 'lib/blather/file_transfer/ibb.rb', line 63 def offer # TODO: implement end |