@@ -19,52 +19,78 @@ module SASL
19
19
class ClientAdapter
20
20
include ProtocolAdapters ::Generic
21
21
22
- attr_reader :client , :command_proc
22
+ # The client that handles communication with the protocol server.
23
+ attr_reader :client
23
24
24
25
# +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 .
29
30
#
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.
32
44
def initialize ( client , &command_proc )
33
45
@client , @command_proc = client , command_proc
34
46
end
35
47
36
- # Delegates to AuthenticationExchange.authenticate.
48
+ # Attempt to authenticate #client to the server.
49
+ #
50
+ # By default, this simply delegates to
51
+ # AuthenticationExchange.authenticate.
37
52
def authenticate ( ...) AuthenticationExchange . authenticate ( self , ...) end
38
53
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>.
40
57
def sasl_ir_capable? ; client . sasl_ir_capable? end
41
58
42
59
# Does the server advertise support for the mechanism?
60
+ #
61
+ # By default, this simply delegates to <tt>client.auth_capable?</tt>.
43
62
def auth_capable? ( mechanism ) ; client . auth_capable? ( mechanism ) end
44
63
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.
47
69
#
48
70
# Yields each continuation payload, responds to the server with the
49
71
# result of each yield, and returns the result. Non-successful results
50
72
# *MUST* raise an exception. Exceptions in the block *MUST* cause the
51
73
# command to fail.
52
74
#
53
75
# 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 )
55
77
command_proc or raise Error , "initialize with block or override"
56
78
args = [ command_name , mechanism , initial_response ] . compact
57
- command_proc . call ( *args , &block )
79
+ command_proc . call ( *args , &continuations_handler )
58
80
end
59
81
60
82
# Returns an array of server responses errors raised by run_command.
61
83
# Exceptions in this array won't drop the connection.
62
84
def response_errors ; [ ] end
63
85
64
86
# Drop the connection gracefully.
87
+ #
88
+ # By default, this simply delegates to <tt>client.drop_connection</tt>.
65
89
def drop_connection ; client . drop_connection end
66
90
67
91
# Drop the connection abruptly.
92
+ #
93
+ # By default, this simply delegates to <tt>client.drop_connection!</tt>.
68
94
def drop_connection! ; client . drop_connection! end
69
95
end
70
96
end
0 commit comments