@@ -19,52 +19,78 @@ module SASL
1919 class ClientAdapter
2020 include ProtocolAdapters ::Generic
2121
22- attr_reader :client , :command_proc
22+ # The client that handles communication with the protocol server.
23+ attr_reader :client
2324
2425 # +command_proc+ can used to avoid exposing private methods on #client.
25- # It should run a command with the arguments sent to it, yield each
26- # continuation payload, respond to the server with the result of each
27- # yield, and return the result. Non-successful results *MUST* raise an
28- # exception. Exceptions in the block *MUST* cause the command to fail .
26+ # It's value is set by the block that is passed to ::new, and it is used
27+ # by the default implementation of #run_command. Subclasses that
28+ # override #run_command may use #command_proc for any other purpose they
29+ # find useful .
2930 #
30- # Subclasses that override #run_command may use #command_proc for
31- # other purposes.
31+ # In the default implementation of #run_command, command_proc is called
32+ # with the protocols authenticate +command+ name, the +mechanism+ name,
33+ # an _optional_ +initial_response+ argument, and a +continuations+
34+ # block. command_proc must run the protocol command with the arguments
35+ # sent to it, _yield_ the payload of each continuation, respond to the
36+ # continuation with the result of each _yield_, and _return_ the
37+ # command's successful result. Non-successful results *MUST* raise
38+ # an exception.
39+ attr_reader :command_proc
40+
41+ # By default, this simply sets the #client and #command_proc attributes.
42+ # Subclasses may override it, for example: to set the appropriate
43+ # command_proc automatically.
3244 def initialize ( client , &command_proc )
3345 @client , @command_proc = client , command_proc
3446 end
3547
36- # Delegates to AuthenticationExchange.authenticate.
48+ # Attempt to authenticate #client to the server.
49+ #
50+ # By default, this simply delegates to
51+ # AuthenticationExchange.authenticate.
3752 def authenticate ( ...) AuthenticationExchange . authenticate ( self , ...) end
3853
39- # Do the protocol and server both support an initial response?
54+ # Do the protocol, server, and client all support an initial response?
55+ #
56+ # By default, this simply delegates to <tt>client.sasl_ir_capable?</tt>.
4057 def sasl_ir_capable? ; client . sasl_ir_capable? end
4158
4259 # Does the server advertise support for the mechanism?
60+ #
61+ # By default, this simply delegates to <tt>client.auth_capable?</tt>.
4362 def auth_capable? ( mechanism ) ; client . auth_capable? ( mechanism ) end
4463
45- # Runs the authenticate command with +mechanism+ and +initial_response+.
46- # When +initial_response+ is nil, an initial response must NOT be sent.
64+ # Calls command_proc with +command_name+ (see
65+ # SASL::ProtocolAdapters::Generic#command_name),
66+ # +mechanism+, +initial_response+, and a +continuations_handler+ block.
67+ # The +initial_response+ is optional; when it's nil, it won't be sent to
68+ # command_proc.
4769 #
4870 # Yields each continuation payload, responds to the server with the
4971 # result of each yield, and returns the result. Non-successful results
5072 # *MUST* raise an exception. Exceptions in the block *MUST* cause the
5173 # command to fail.
5274 #
5375 # Subclasses that override this may use #command_proc differently.
54- def run_command ( mechanism , initial_response = nil , &block )
76+ def run_command ( mechanism , initial_response = nil , &continuations_handler )
5577 command_proc or raise Error , "initialize with block or override"
5678 args = [ command_name , mechanism , initial_response ] . compact
57- command_proc . call ( *args , &block )
79+ command_proc . call ( *args , &continuations_handler )
5880 end
5981
6082 # Returns an array of server responses errors raised by run_command.
6183 # Exceptions in this array won't drop the connection.
6284 def response_errors ; [ ] end
6385
6486 # Drop the connection gracefully.
87+ #
88+ # By default, this simply delegates to <tt>client.drop_connection</tt>.
6589 def drop_connection ; client . drop_connection end
6690
6791 # Drop the connection abruptly.
92+ #
93+ # By default, this simply delegates to <tt>client.drop_connection!</tt>.
6894 def drop_connection! ; client . drop_connection! end
6995 end
7096 end
0 commit comments