Class: HrrRbSftp::Protocol
- Inherits:
-
Object
- Object
- HrrRbSftp::Protocol
- Includes:
- Loggable
- Defined in:
- lib/hrr_rb_sftp/protocol.rb,
lib/hrr_rb_sftp/protocol/common.rb,
lib/hrr_rb_sftp/protocol/version1.rb,
lib/hrr_rb_sftp/protocol/version2.rb,
lib/hrr_rb_sftp/protocol/version3.rb,
lib/hrr_rb_sftp/protocol/common/packet.rb,
lib/hrr_rb_sftp/protocol/version1/packet.rb,
lib/hrr_rb_sftp/protocol/version2/packet.rb,
lib/hrr_rb_sftp/protocol/version3/packet.rb,
lib/hrr_rb_sftp/protocol/common/data_type.rb,
lib/hrr_rb_sftp/protocol/common/packetable.rb,
lib/hrr_rb_sftp/protocol/version1/data_type.rb,
lib/hrr_rb_sftp/protocol/version2/data_type.rb,
lib/hrr_rb_sftp/protocol/version3/data_type.rb,
lib/hrr_rb_sftp/protocol/common/data_type/byte.rb,
lib/hrr_rb_sftp/protocol/common/data_type/string.rb,
lib/hrr_rb_sftp/protocol/common/data_type/uint32.rb,
lib/hrr_rb_sftp/protocol/common/data_type/uint64.rb,
lib/hrr_rb_sftp/protocol/version1/data_type/attrs.rb,
lib/hrr_rb_sftp/protocol/common/packet/001_ssh_fxp_init.rb,
lib/hrr_rb_sftp/protocol/common/data_type/extension_pair.rb,
lib/hrr_rb_sftp/protocol/common/data_type/extension_pairs.rb,
lib/hrr_rb_sftp/protocol/version1/packet/003_ssh_fxp_open.rb,
lib/hrr_rb_sftp/protocol/version1/packet/005_ssh_fxp_read.rb,
lib/hrr_rb_sftp/protocol/version1/packet/017_ssh_fxp_stat.rb,
lib/hrr_rb_sftp/protocol/version1/packet/103_ssh_fxp_data.rb,
lib/hrr_rb_sftp/protocol/version1/packet/104_ssh_fxp_name.rb,
lib/hrr_rb_sftp/protocol/common/packet/002_ssh_fxp_version.rb,
lib/hrr_rb_sftp/protocol/version1/packet/004_ssh_fxp_close.rb,
lib/hrr_rb_sftp/protocol/version1/packet/006_ssh_fxp_write.rb,
lib/hrr_rb_sftp/protocol/version1/packet/007_ssh_fxp_lstat.rb,
lib/hrr_rb_sftp/protocol/version1/packet/008_ssh_fxp_fstat.rb,
lib/hrr_rb_sftp/protocol/version1/packet/014_ssh_fxp_mkdir.rb,
lib/hrr_rb_sftp/protocol/version1/packet/015_ssh_fxp_rmdir.rb,
lib/hrr_rb_sftp/protocol/version1/packet/105_ssh_fxp_attrs.rb,
lib/hrr_rb_sftp/protocol/version3/packet/014_ssh_fxp_mkdir.rb,
lib/hrr_rb_sftp/protocol/version1/packet/013_ssh_fxp_remove.rb,
lib/hrr_rb_sftp/protocol/version1/packet/101_ssh_fxp_status.rb,
lib/hrr_rb_sftp/protocol/version1/packet/102_ssh_fxp_handle.rb,
lib/hrr_rb_sftp/protocol/version2/packet/018_ssh_fxp_rename.rb,
lib/hrr_rb_sftp/protocol/version3/packet/101_ssh_fxp_status.rb,
lib/hrr_rb_sftp/protocol/version1/packet/009_ssh_fxp_setstat.rb,
lib/hrr_rb_sftp/protocol/version1/packet/011_ssh_fxp_opendir.rb,
lib/hrr_rb_sftp/protocol/version1/packet/012_ssh_fxp_readdir.rb,
lib/hrr_rb_sftp/protocol/version3/packet/020_ssh_fxp_symlink.rb,
lib/hrr_rb_sftp/protocol/version1/packet/010_ssh_fxp_fsetstat.rb,
lib/hrr_rb_sftp/protocol/version1/packet/016_ssh_fxp_realpath.rb,
lib/hrr_rb_sftp/protocol/version3/packet/019_ssh_fxp_readlink.rb,
lib/hrr_rb_sftp/protocol/version3/packet/200_ssh_fxp_extended.rb,
lib/hrr_rb_sftp/protocol/version3/packet/201_ssh_fxp_extended_reply.rb
Defined Under Namespace
Modules: Common Classes: Version1, Version2, Version3
Instance Attribute Summary
Attributes included from Loggable
Class Method Summary collapse
Instance Method Summary collapse
- #close_handles ⇒ Object
-
#initialize(version, logger: nil) ⇒ Protocol
constructor
A new instance of Protocol.
- #respond_to(request_payload) ⇒ Object
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn
Constructor Details
#initialize(version, logger: nil) ⇒ Protocol
Returns a new instance of Protocol.
9 10 11 12 13 14 15 16 17 |
# File 'lib/hrr_rb_sftp/protocol.rb', line 9 def initialize version, logger: nil self.logger = logger @handles = Hash.new @version = version @version_class = self.class.const_get(:"Version#{@version}") packet_classes = @version_class::Packet.constants.select{|c| c.to_s.start_with?("SSH_FXP_")}.map{|c| @version_class::Packet.const_get(c)} @packets = packet_classes.map{|pkt| [pkt::TYPE, pkt.new(@handles, logger: logger)]}.inject(Hash.new){|h,(k,v)| h.update({k => v})} end |
Class Method Details
.versions ⇒ Object
5 6 7 |
# File 'lib/hrr_rb_sftp/protocol.rb', line 5 def self.versions constants.select{|c| c.to_s.start_with?("Version")}.map{|c| const_get(c)}.map{|klass| klass::PROTOCOL_VERSION} end |
Instance Method Details
#close_handles ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/hrr_rb_sftp/protocol.rb', line 48 def close_handles log_info { "closing handles" } @handles.each do |k, v| v.close rescue nil end @handles.clear log_info { "handles closed" } end |
#respond_to(request_payload) ⇒ Object
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 |
# File 'lib/hrr_rb_sftp/protocol.rb', line 19 def respond_to request_payload request_type = request_payload[0].unpack("C")[0] response_packet = if @packets.has_key?(request_type) begin request_packet = @packets[request_type].decode request_payload rescue => e { :"type" => @version_class::Packet::SSH_FXP_STATUS::TYPE, :"request-id" => (request_payload[1,4].unpack("N")[0] || 0), :"code" => @version_class::Packet::SSH_FXP_STATUS::SSH_FX_BAD_MESSAGE, :"error message" => e., :"language tag" => "", } else @packets[request_type].respond_to request_packet end else { :"type" => @version_class::Packet::SSH_FXP_STATUS::TYPE, :"request-id" => (request_payload[1,4].unpack("N")[0] || 0), :"code" => @version_class::Packet::SSH_FXP_STATUS::SSH_FX_OP_UNSUPPORTED, :"error message" => "Unsupported type: #{request_type}", :"language tag" => "", } end response_type = response_packet[:"type"] @packets[response_type].encode response_packet end |