public
Description: Pure Ruby implementation of an SFTP (protocols 1-6) client
Homepage: http://rubyforge.org/projects/net-ssh
Clone URL: git://github.com/jamis/net-sftp.git
refactor constants for better centralization
jamis (author)
Wed Mar 12 07:18:24 -0700 2008
commit  5220262529a8a29ace89469489055a39ee785040
tree    a7a7a051e1fc3ebd0c77644a097919feb05f8d5b
parent  3196fbb9b7897098590f99f7fdd6ff78cb858603
...
5
6
7
8
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
11
12
13
14
15
16
17
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
77
78
...
5
6
7
 
 
8
9
10
11
12
13
14
15
16
17
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
 
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
0
@@ -5,74 +5,105 @@ module Net module SFTP
0
   # meaning and usage.
0
   module Constants
0
 
0
- FXP_INIT = 1
0
- FXP_VERSION = 2
0
+ module PacketTypes
0
+ FXP_INIT = 1
0
+ FXP_VERSION = 2
0
+
0
+ FXP_OPEN = 3
0
+ FXP_CLOSE = 4
0
+ FXP_READ = 5
0
+ FXP_WRITE = 6
0
+ FXP_LSTAT = 7
0
+ FXP_FSTAT = 8
0
+ FXP_SETSTAT = 9
0
+ FXP_FSETSTAT = 10
0
+ FXP_OPENDIR = 11
0
+ FXP_READDIR = 12
0
+ FXP_REMOVE = 13
0
+ FXP_MKDIR = 14
0
+ FXP_RMDIR = 15
0
+ FXP_REALPATH = 16
0
+ FXP_STAT = 17
0
+ FXP_RENAME = 18
0
+ FXP_READLINK = 19
0
+ FXP_SYMLINK = 20
0
+ FXP_LINK = 21
0
+ FXP_BLOCK = 22
0
+ FXP_UNBLOCK = 23
0
+
0
+ FXP_STATUS = 101
0
+ FXP_HANDLE = 102
0
+ FXP_DATA = 103
0
+ FXP_NAME = 104
0
+ FXP_ATTRS = 105
0
+
0
+ FXP_EXTENDED = 106
0
+ FXP_EXTENDED_REPLY = 107
0
+ end
0
 
0
- FXP_OPEN = 3
0
- FXP_CLOSE = 4
0
- FXP_READ = 5
0
- FXP_WRITE = 6
0
- FXP_LSTAT = 7
0
- FXP_FSTAT = 8
0
- FXP_SETSTAT = 9
0
- FXP_FSETSTAT = 10
0
- FXP_OPENDIR = 11
0
- FXP_READDIR = 12
0
- FXP_REMOVE = 13
0
- FXP_MKDIR = 14
0
- FXP_RMDIR = 15
0
- FXP_REALPATH = 16
0
- FXP_STAT = 17
0
- FXP_RENAME = 18
0
- FXP_READLINK = 19
0
- FXP_SYMLINK = 20
0
- FXP_LINK = 21
0
- FXP_BLOCK = 22
0
- FXP_UNBLOCK = 23
0
+ module RenameFlags
0
+ FXP_OVERWRITE = 0x00000001
0
+ FXP_ATOMIC = 0x00000002
0
+ FXP_NATIVE = 0x00000004
0
+ end
0
 
0
- FXP_STATUS = 101
0
- FXP_HANDLE = 102
0
- FXP_DATA = 103
0
- FXP_NAME = 104
0
- FXP_ATTRS = 105
0
+ module StatusCodes
0
+ FX_OK = 0
0
+ FX_EOF = 1
0
+ FX_NO_SUCH_FILE = 2
0
+ FX_PERMISSION_DENIED = 3
0
+ FX_FAILURE = 4
0
+ FX_BAD_MESSAGE = 5
0
+ FX_NO_CONNECTION = 6
0
+ FX_CONNECTION_LOST = 7
0
+ FX_OP_UNSUPPORTED = 8
0
+ FX_INVALID_HANDLE = 9
0
+ FX_NO_SUCH_PATH = 10
0
+ FX_FILE_ALREADY_EXISTS = 11
0
+ FX_WRITE_PROTECT = 12
0
+ FX_NO_MEDIA = 13
0
+ FX_NO_SPACE_ON_FILESYSTEM = 14
0
+ FX_QUOTA_EXCEEDED = 15
0
+ FX_UNKNOWN_PRINCIPLE = 16
0
+ FX_LOCK_CONFlICT = 17
0
+ FX_DIR_NOT_EMPTY = 18
0
+ FX_NOT_A_DIRECTORY = 19
0
+ FX_INVALID_FILENAME = 20
0
+ FX_LINK_LOOP = 21
0
+ end
0
 
0
- FXP_EXTENDED = 106
0
- FXP_EXTENDED_REPLY = 107
0
+ module ACE
0
+ T_ACCESS_ALLOWED = 0x00000000
0
+ T_ACCESS_DENIED = 0x00000001
0
+ T_SYSTEM_AUDIT = 0x00000002
0
+ T_SYSTEM_ALARM = 0x00000003
0
+
0
+ FL_FILE_INHERIT = 0x00000001
0
+ FL_DIRECTORY_INHERIT = 0x00000002
0
+ FL_NO_PROPAGATE_INHERIT = 0x00000004
0
+ FL_INHERIT_ONLY = 0x00000008
0
+ FL_SUCCESSFUL_ACCESS = 0x00000010
0
+ FL_FAILED_ACCESS = 0x00000020
0
+ FL_IDENTIFIER_GROUP = 0x00000040
0
 
0
- FXP_RENAME_OVERWRITE = 0x00000001
0
- FXP_RENAME_ATOMIC = 0x00000002
0
- FXP_RENAME_NATIVE = 0x00000004
0
-
0
- ACE4_ACCESS_ALLOWED_ACE_TYPE = 0x00000000
0
- ACE4_ACCESS_DENIED_ACE_TYPE = 0x00000001
0
- ACE4_SYSTEM_AUDIT_ACE_TYPE = 0x00000002
0
- ACE4_SYSTEM_ALARM_ACE_TYPE = 0x00000003
0
-
0
- ACE4_FILE_INHERIT_ACE = 0x00000001
0
- ACE4_DIRECTORY_INHERIT_ACE = 0x00000002
0
- ACE4_NO_PROPAGATE_INHERIT_ACE = 0x00000004
0
- ACE4_INHERIT_ONLY_ACE = 0x00000008
0
- ACE4_SUCCESSFUL_ACCESS_ACE_FLAG = 0x00000010
0
- ACE4_FAILED_ACCESS_ACE_FLAG = 0x00000020
0
- ACE4_IDENTIFIER_GROUP = 0x00000040
0
-
0
- ACE4_READ_DATA = 0x00000001
0
- ACE4_LIST_DIRECTORY = 0x00000001
0
- ACE4_WRITE_DATA = 0x00000002
0
- ACE4_ADD_FILE = 0x00000002
0
- ACE4_APPEND_DATA = 0x00000004
0
- ACE4_ADD_SUBDIRECTORY = 0x00000004
0
- ACE4_READ_NAMED_ATTRS = 0x00000008
0
- ACE4_WRITE_NAMED_ATTRS = 0x00000010
0
- ACE4_EXECUTE = 0x00000020
0
- ACE4_DELETE_CHILD = 0x00000040
0
- ACE4_READ_ATTRIBUTES = 0x00000080
0
- ACE4_WRITE_ATTRIBUTES = 0x00000100
0
- ACE4_DELETE = 0x00010000
0
- ACE4_READ_ACL = 0x00020000
0
- ACE4_WRITE_ACL = 0x00040000
0
- ACE4_WRITE_OWNER = 0x00080000
0
- ACE4_SYNCHRONIZE = 0x00100000
0
+ F_READ_DATA = 0x00000001
0
+ F_LIST_DIRECTORY = 0x00000001
0
+ F_WRITE_DATA = 0x00000002
0
+ F_ADD_FILE = 0x00000002
0
+ F_APPEND_DATA = 0x00000004
0
+ F_ADD_SUBDIRECTORY = 0x00000004
0
+ F_READ_NAMED_ATTRS = 0x00000008
0
+ F_WRITE_NAMED_ATTRS = 0x00000010
0
+ F_EXECUTE = 0x00000020
0
+ F_DELETE_CHILD = 0x00000040
0
+ F_READ_ATTRIBUTES = 0x00000080
0
+ F_WRITE_ATTRIBUTES = 0x00000100
0
+ F_DELETE = 0x00010000
0
+ F_READ_ACL = 0x00020000
0
+ F_WRITE_ACL = 0x00040000
0
+ F_WRITE_OWNER = 0x00080000
0
+ F_SYNCHRONIZE = 0x00100000
0
+ end
0
 
0
   end
0
 
...
49
50
51
52
 
53
54
55
...
49
50
51
 
52
53
54
55
0
@@ -49,7 +49,7 @@ module Net; module SFTP; module Protocol; module V04
0
     T_FIFO = 9
0
 
0
     # A simple struct for representing a single entry in an Access Control
0
- # List.
0
+ # List. (See Net::SFTP::Constants::ACE)
0
     ACL = Struct.new(:type, :flag, :mask, :who)
0
 
0
     class <<self
...
3
4
5
 
6
7
8
...
17
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
...
3
4
5
6
7
8
9
...
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
0
@@ -3,6 +3,7 @@ require 'net/sftp/protocol/04/base'
0
 module Net; module SFTP; module Protocol; module V05
0
 
0
   class Base < V04::Base
0
+ include Net::SFTP::Constants
0
 
0
     F_CREATE_NEW = 0x00000000
0
     F_CREATE_TRUNCATE = 0x00000001
0
@@ -17,26 +18,6 @@ module Net; module SFTP; module Protocol; module V05
0
     F_WRITE_LOCK = 0x00000080
0
     F_DELETE_LOCK = 0x00000100
0
 
0
- module ACE
0
- F_READ_DATA = 0x00000001
0
- F_LIST_DIRECTORY = 0x00000001
0
- F_WRITE_DATA = 0x00000002
0
- F_ADD_FILE = 0x00000002
0
- F_APPEND_DATA = 0x00000004
0
- F_ADD_SUBDIRECTORY = 0x00000004
0
- F_READ_NAMED_ATTRS = 0x00000008
0
- F_WRITE_NAMED_ATTRS = 0x00000010
0
- F_EXECUTE = 0x00000020
0
- F_DELETE_CHILD = 0x00000040
0
- F_READ_ATTRIBUTES = 0x00000080
0
- F_WRITE_ATTRIBUTES = 0x00000100
0
- F_DELETE = 0x00010000
0
- F_READ_ACL = 0x00020000
0
- F_WRITE_ACL = 0x00040000
0
- F_WRITE_OWNER = 0x00080000
0
- F_SYNCHRONIZE = 0x00100000
0
- end
0
-
0
     def version
0
       5
0
     end
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@ module Net; module SFTP; module Protocol
0
   # provides a way for subclasses to send requests.
0
   class Base
0
     include Net::SSH::Loggable
0
- include Net::SFTP::Constants
0
+ include Net::SFTP::Constants::PacketTypes
0
 
0
     # The SFTP session object that acts as client to this protocol instance
0
     attr_reader :session
...
13
14
15
16
 
17
18
19
...
13
14
15
 
16
17
18
19
0
@@ -13,7 +13,7 @@ module Net; module SFTP
0
   # puts request.pending? #-> false
0
   # result = request.response
0
   class Request
0
- include Constants
0
+ include Constants::PacketTypes
0
 
0
     # The Net::SFTP session object that is servicing this request
0
     attr_reader :session
...
 
 
1
2
3
...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
37
38
39
...
1
2
3
4
5
...
14
15
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
18
19
20
0
@@ -1,3 +1,5 @@
0
+require 'net/sftp/constants'
0
+
0
 module Net; module SFTP
0
 
0
   # Encapsulates a response from the remote server, to a specific client
0
@@ -12,28 +14,7 @@ module Net; module SFTP
0
   #
0
   # sftp.loop
0
   class Response
0
- FX_OK = 0
0
- FX_EOF = 1
0
- FX_NO_SUCH_FILE = 2
0
- FX_PERMISSION_DENIED = 3
0
- FX_FAILURE = 4
0
- FX_BAD_MESSAGE = 5
0
- FX_NO_CONNECTION = 6
0
- FX_CONNECTION_LOST = 7
0
- FX_OP_UNSUPPORTED = 8
0
- FX_INVALID_HANDLE = 9
0
- FX_NO_SUCH_PATH = 10
0
- FX_FILE_ALREADY_EXISTS = 11
0
- FX_WRITE_PROTECT = 12
0
- FX_NO_MEDIA = 13
0
- FX_NO_SPACE_ON_FILESYSTEM = 14
0
- FX_QUOTA_EXCEEDED = 15
0
- FX_UNKNOWN_PRINCIPLE = 16
0
- FX_LOCK_CONFlICT = 17
0
- FX_DIR_NOT_EMPTY = 18
0
- FX_NOT_A_DIRECTORY = 19
0
- FX_INVALID_FILENAME = 20
0
- FX_LINK_LOOP = 21
0
+ include Net::SFTP::Constants::StatusCodes
0
 
0
     # The request object that this object is in response to
0
     attr_reader :request
...
43
44
45
46
 
47
48
49
...
43
44
45
 
46
47
48
49
0
@@ -43,7 +43,7 @@ module Net; module SFTP
0
   # run in order to process these requests. (See #loop.)
0
   class Session
0
     include Net::SSH::Loggable
0
- include Net::SFTP::Constants
0
+ include Net::SFTP::Constants::PacketTypes
0
 
0
     # The highest protocol version supported by the Net::SFTP library.
0
     HIGHEST_PROTOCOL_VERSION_SUPPORTED = 6
...
22
23
24
25
 
26
27
28
...
22
23
24
 
25
26
27
28
0
@@ -22,7 +22,7 @@ require 'net/sftp/constants'
0
 require 'net/ssh/test'
0
 
0
 class Net::SFTP::TestCase < Test::Unit::TestCase
0
- include Net::SFTP::Constants
0
+ include Net::SFTP::Constants::PacketTypes
0
   include Net::SSH::Test
0
 
0
   def default_test
...
6
7
8
9
 
10
11
12
13
14
15
 
16
17
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
...
6
7
8
 
9
10
11
12
13
14
 
15
16
17
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
0
@@ -6,37 +6,37 @@ class Protocol::TestBase < Net::SFTP::TestCase
0
   end
0
 
0
   def test_parse_with_status_packet_should_delegate_to_parse_status_packet
0
- packet = stub('packet', :type => Net::SFTP::Constants::FXP_STATUS)
0
+ packet = stub('packet', :type => FXP_STATUS)
0
     @base.expects(:parse_status_packet).with(packet).returns(:result)
0
     assert_equal :result, @base.parse(packet)
0
   end
0
 
0
   def test_parse_with_handle_packet_should_delegate_to_parse_handle_packet
0
- packet = stub('packet', :type => Net::SFTP::Constants::FXP_HANDLE)
0
+ packet = stub('packet', :type => FXP_HANDLE)
0
     @base.expects(:parse_handle_packet).with(packet).returns(:result)
0
     assert_equal :result, @base.parse(packet)
0
   end
0
 
0
   def test_parse_with_data_packet_should_delegate_to_parse_data_packet
0
- packet = stub('packet', :type => Net::SFTP::Constants::FXP_DATA)
0
+ packet = stub('packet', :type => FXP_DATA)
0
     @base.expects(:parse_data_packet).with(packet).returns(:result)
0
     assert_equal :result, @base.parse(packet)
0
   end
0
 
0
   def test_parse_with_name_packet_should_delegate_to_parse_name_packet
0
- packet = stub('packet', :type => Net::SFTP::Constants::FXP_NAME)
0
+ packet = stub('packet', :type => FXP_NAME)
0
     @base.expects(:parse_name_packet).with(packet).returns(:result)
0
     assert_equal :result, @base.parse(packet)
0
   end
0
 
0
   def test_parse_with_attrs_packet_should_delegate_to_parse_attrs_packet
0
- packet = stub('packet', :type => Net::SFTP::Constants::FXP_ATTRS)
0
+ packet = stub('packet', :type => FXP_ATTRS)
0
     @base.expects(:parse_attrs_packet).with(packet).returns(:result)
0
     assert_equal :result, @base.parse(packet)
0
   end
0
 
0
   def test_parse_with_unknown_packet_should_raise_exception
0
- packet = stub('packet', :type => Net::SFTP::Constants::FXP_WRITE)
0
+ packet = stub('packet', :type => FXP_WRITE)
0
     assert_raises(NotImplementedError) { @base.parse(packet) }
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.