lib/net/ldap.rb in net-ldap-0.2 vs lib/net/ldap.rb in net-ldap-0.2.1

- old
+ new

@@ -239,11 +239,11 @@ # operation (typically binding first) and then disconnect from the server. # The exception is Net::LDAP#open, which makes a connection to the server # and then keeps it open while it executes a user-supplied block. # Net::LDAP#open closes the connection on completion of the block. class Net::LDAP - VERSION = "0.2" + VERSION = "0.2.1" class LdapError < StandardError; end SearchScope_BaseObject = 0 SearchScope_SingleLevel = 1 @@ -1450,22 +1450,29 @@ } # loop result_code end - def self.modify_ops args - modify_ops = [] - a = args[:operations] and a.each {|op, attr, values| - # TODO, fix the following line, which gives a bogus error - # if the opcode is invalid. - op_1 = {:add => 0, :delete => 1, :replace => 2} [op.to_sym].to_ber_enumerated - values = [values].flatten.map { |v| - v.to_ber unless v.nil? - }.to_ber_set - modify_ops << [op_1,[attr.to_s.to_ber,values].to_ber_sequence].to_ber + MODIFY_OPERATIONS = { #:nodoc: + :add => 0, + :delete => 1, + :replace => 2 + } + + def self.modify_ops(operations) + modify_ops = [] + if operations + operations.each { |op, attrib, values| + # TODO, fix the following line, which gives a bogus error if the + # opcode is invalid. + op_ber = MODIFY_OPERATIONS[op.to_sym].to_ber_enumerated + values = [ values ].flatten.map { |v| v.to_ber if v }.to_ber_set + values = [ attrib.to_s.to_ber, values ].to_ber_sequence + modify_ops << [ op_ber, values ].to_ber } - modify_ops + end + modify_ops end #-- # TODO: need to support a time limit, in case the server fails to respond. # TODO: We're throwing an exception here on empty DN. Should return a @@ -1474,12 +1481,12 @@ # error here ("to_ber_enumerated is not defined on nil"). #++ def modify(args) modify_dn = args[:dn] or raise "Unable to modify empty DN" modify_ops = modify_ops args[:operations] - request = [modify_dn.to_ber, - modify_ops.to_ber_sequence].to_ber_appsequence(6) - pkt = [next_msgid.to_ber, request].to_ber_sequence + request = [ modify_dn.to_ber, + modify_ops.to_ber_sequence ].to_ber_appsequence(6) + pkt = [ next_msgid.to_ber, request ].to_ber_sequence @conn.write pkt (be = @conn.read_ber(Net::LDAP::AsnSyntax)) && (pdu = Net::LDAP::PDU.new(be)) && (pdu.app_tag == 7) or raise Net::LDAP::LdapError, "response missing or invalid" pdu.result_code end