Class: Ftpd::CommandSequenceChecker

Inherits:
Object
  • Object
show all
Includes:
Error
Defined in:
lib/ftpd/command_sequence_checker.rb

Instance Method Summary collapse

Methods included from Error

#error, #permanent_error, #sequence_error, #transient_error, #unimplemented_error, #unrecognized_error

Constructor Details

#initializeCommandSequenceChecker

Returns a new instance of CommandSequenceChecker.



12
13
14
# File 'lib/ftpd/command_sequence_checker.rb', line 12

def initialize
  @must_expect = []
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, unless #expect is called again.

Parameters:

  • command (String)

    The command. Must be lowercase.

Raises:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ftpd/command_sequence_checker.rb', line 43

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.

Parameters:

  • command (String)

    The command. Must be lowercase.



22
23
24
# File 'lib/ftpd/command_sequence_checker.rb', line 22

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.



30
31
32
# File 'lib/ftpd/command_sequence_checker.rb', line 30

def must_expect(command)
  @must_expect << command
end