Class: Ftpd::CommandSequenceChecker
- Inherits:
-
Object
- Object
- Ftpd::CommandSequenceChecker
- Includes:
- Error
- Defined in:
- lib/ftpd/command_sequence_checker.rb
Instance Method Summary collapse
-
#check(command) ⇒ Object
Check a command.
-
#expect(command) ⇒ Object
Set the command to expect next.
-
#initialize ⇒ CommandSequenceChecker
constructor
A new instance of CommandSequenceChecker.
-
#must_expect(command) ⇒ Object
Register a command that must be expected.
Methods included from Error
#error, #sequence_error, #syntax_error, #unimplemented_error
Constructor Details
#initialize ⇒ CommandSequenceChecker
Returns a new instance of CommandSequenceChecker.
14 15 16 17 |
# File 'lib/ftpd/command_sequence_checker.rb', line 14 def initialize @must_expect = [] @expected_command = nil end |
Instance Method Details
#check(command) ⇒ Object
Check a command. If expecting a specific command and this command isn’t it, then raise an error that will cause a “503 Bad sequence” error to be sent. After checking, the expected command is cleared and any command will be accepted until #expect is called again.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ftpd/command_sequence_checker.rb', line 47 def check(command) if @expected_command begin sequence_error unless command == @expected_command ensure @expected_command = nil end else sequence_error if @must_expect.include?(command) end end |
#expect(command) ⇒ Object
Set the command to expect next. If not set, then any command will be accepted, so long as it hasn’t been registered using #must_expect. Otherwise, the set command must be next or a sequence error will result.
26 27 28 |
# File 'lib/ftpd/command_sequence_checker.rb', line 26 def expect(command) @expected_command = command end |
#must_expect(command) ⇒ Object
Register a command that must be expected. When that command is received without #expect having been called for it, a sequence error will result.
34 35 36 |
# File 'lib/ftpd/command_sequence_checker.rb', line 34 def must_expect(command) @must_expect << command end |