Class: HrrRbSftp::Protocol::Version3::Extensions

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/hrr_rb_sftp/protocol/version3/extensions.rb,
lib/hrr_rb_sftp/protocol/version3/extensions/extension.rb,
lib/hrr_rb_sftp/protocol/version3/extensions/fsync_at_openssh_com.rb,
lib/hrr_rb_sftp/protocol/version3/extensions/hardlink_at_openssh_com.rb,
lib/hrr_rb_sftp/protocol/version3/extensions/lsetstat_at_openssh_com.rb,
lib/hrr_rb_sftp/protocol/version3/extensions/posix_rename_at_openssh_com.rb

Overview

This class implements SFTP protocol version 3 extension formats and responders.

Defined Under Namespace

Classes: Extension, FsyncAtOpensshCom, HardlinkAtOpensshCom, LsetstatAtOpensshCom, PosixRenameAtOpensshCom

Instance Attribute Summary

Attributes included from Loggable

#logger

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn

Constructor Details

#initialize(context, logger: nil) ⇒ Extensions

Returns a new instance of Extensions.

Parameters:

  • context (Hash)

    Contextual variables.

    • :version (Integer) - Negotiated protocol version.

    • :handles (Hash{String=>File, Dir}) - Opened handles.

  • logger (Logger) (defaults to: nil)

    Logger.



31
32
33
34
35
36
37
38
39
40
# File 'lib/hrr_rb_sftp/protocol/version3/extensions.rb', line 31

def initialize context, logger: nil
  self.logger = logger

  @conditional_request_format = conditional_request_format
  @conditional_reply_format   = conditional_reply_format
  @extensions = extension_classes.map{ |c|
                  extension = c.new(context, logger: logger)
                  (c::REQUEST_FORMAT[:"extended-request"] || {}).keys.map{|key| {key => extension} }.inject({}, :merge)
                }.inject({}, :merge)
end

Class Method Details

.extension_classesArray<Class>

Returns A list of classes that has EXTENSION_NAME constant.

Returns:

  • (Array<Class>)

    A list of classes that has EXTENSION_NAME constant.



14
15
16
# File 'lib/hrr_rb_sftp/protocol/version3/extensions.rb', line 14

def self.extension_classes
  constants.map{|c| const_get(c)}.select{|c| c.respond_to?(:const_defined?) && c.const_defined?(:EXTENSION_NAME)}
end

.extension_pairsArray

Returns A list of extension-pair that the library supports.

Returns:

  • (Array)

    A list of extension-pair that the library supports.



21
22
23
# File 'lib/hrr_rb_sftp/protocol/version3/extensions.rb', line 21

def self.extension_pairs
  extension_classes.map{|c| {:"extension-name" => c::EXTENSION_NAME, :"extension-data" => c::EXTENSION_DATA}}
end

Instance Method Details

#conditional_reply_formatHash{Symbol=>Hash{String=>Array<Array(Object, Symbol)>}}

Returns Conditional format used in extended-reply packet.

Returns:

  • (Hash{Symbol=>Hash{String=>Array<Array(Object, Symbol)>}})

    Conditional format used in extended-reply packet.



68
69
70
# File 'lib/hrr_rb_sftp/protocol/version3/extensions.rb', line 68

def conditional_reply_format
  @conditional_reply_format ||= reply_formats.inject({}){|h1,h2| h1.merge(h2){|k,v1,v2| v1.merge(v2)}}
end

#conditional_request_formatHash{Symbol=>Hash{String=>Array<Array(Object, Symbol)>}}

Returns Conditional format used in extended-request packet.

Returns:

  • (Hash{Symbol=>Hash{String=>Array<Array(Object, Symbol)>}})

    Conditional format used in extended-request packet.



61
62
63
# File 'lib/hrr_rb_sftp/protocol/version3/extensions.rb', line 61

def conditional_request_format
  @conditional_request_format ||= request_formats.inject({}){|h1,h2| h1.merge(h2){|k,v1,v2| v1.merge(v2)}}
end

#respond_to(request) ⇒ Hash{Symbol=>Object] Response represented in Hash.

Returns Hash{Symbol=>Object] Response represented in Hash.

Returns:

  • (Hash{Symbol=>Object] Response represented in Hash.)

    Hash{Symbol=>Object] Response represented in Hash.



53
54
55
56
# File 'lib/hrr_rb_sftp/protocol/version3/extensions.rb', line 53

def respond_to request
  extended_request = request[:"extended-request"]
  @extensions[extended_request].respond_to request
end

#respond_to?(request) ⇒ Boolean

Returns true if request’s extended-request is supported. false if not.

Returns:

  • (Boolean)

    true if request’s extended-request is supported. false if not.



45
46
47
48
# File 'lib/hrr_rb_sftp/protocol/version3/extensions.rb', line 45

def respond_to? request
  extended_request = request[:"extended-request"]
  @extensions.has_key?(extended_request)
end