extended our support for error messages returned from servers.

This commit is contained in:
blackhedd 2007-03-20 18:28:34 +00:00
parent 17dcc52e05
commit 789b36c9d7
3 changed files with 27 additions and 2 deletions

View file

@ -26,6 +26,8 @@
* Added missing synactic support for Filter ANDs, NOTs and a few other * Added missing synactic support for Filter ANDs, NOTs and a few other
things. things.
* Added some support for SNMP data-handling. * Added some support for SNMP data-handling.
* Extended support for server-reported error messages. This was provisionally
added to Net::LDAP#add, and eventually will be added to other methods.
== Net::LDAP 0.0.4: August 15, 2006 == Net::LDAP 0.0.4: August 15, 2006

View file

@ -510,9 +510,17 @@ module Net
# puts "Message: #{ldap.get_operation_result.message}" # puts "Message: #{ldap.get_operation_result.message}"
# end # end
# #
#--
# Modified the implementation, 20Mar07. We might get a hash of LDAP response codes
# instead of a simple numeric code.
#
def get_operation_result def get_operation_result
os = OpenStruct.new os = OpenStruct.new
if @result if @result.is_a?(Hash)
os.code = (@result[:resultCode] || "").to_i
os.error_message = @result[:errorMessage]
os.matched_dn = @result[:matchedDN]
elsif @result
os.code = @result os.code = @result
else else
os.code = 0 os.code = 0
@ -802,6 +810,9 @@ module Net
# Net::LDAP.open (:host => host) do |ldap| # Net::LDAP.open (:host => host) do |ldap|
# ldap.add( :dn => dn, :attributes => attr ) # ldap.add( :dn => dn, :attributes => attr )
# end # end
#--
# Provisional modification: Connection#add returns a full hash with LDAP status values,
# instead of the simple result number we're used to getting.
# #
def add args def add args
if @open_connection if @open_connection
@ -1421,6 +1432,10 @@ module Net
#-- #--
# add # add
# TODO, need to support a time limit, in case the server fails to respond. # TODO, need to support a time limit, in case the server fails to respond.
# Unlike other operation-methods in this class, we return a result hash rather
# than a simple result number. This is experimental, and eventually we'll want
# to do this with all the others. The point is to have access to the error message
# and the matched-DN returned by the server.
# #
def add args def add args
add_dn = args[:dn] or raise LdapError.new("Unable to add empty DN") add_dn = args[:dn] or raise LdapError.new("Unable to add empty DN")
@ -1434,7 +1449,7 @@ module Net
@conn.write pkt @conn.write pkt
(be = @conn.read_ber(AsnSyntax)) && (pdu = LdapPdu.new( be )) && (pdu.app_tag == 9) or raise LdapError.new( "response missing or invalid" ) (be = @conn.read_ber(AsnSyntax)) && (pdu = LdapPdu.new( be )) && (pdu.app_tag == 9) or raise LdapError.new( "response missing or invalid" )
pdu.result_code pdu.result
end end

View file

@ -119,6 +119,14 @@ class LdapPdu
end end
end end
# Returns a hash which (usually) defines the members :resultCode, :errorMessage, and :matchedDN.
# These values come directly from an LDAP response packet returned by the remote peer.
# See #result_code for a sugaring.
#
def result
@ldap_result || {}
end
# #
# result_code # result_code
# This returns an LDAP result code taken from the PDU, # This returns an LDAP result code taken from the PDU,