class LDAP::Conn

def assert_error_code

def assert_error_code
  return unless failed?
  code = error_code
  message = error_message
  klass = ActiveLdap::LdapError::ERRORS[code]
  klass ||= IMPLEMENT_SPECIFIC_ERRORS[code]
  if klass.nil? and message == "Can't contact LDAP server"
    klass = ActiveLdap::ConnectionError
  end
  klass ||= ActiveLdap::LdapError
  raise klass, message
end

def error_code

def error_code
  code = err
  code = get_option(LDAP_OPT_ERROR_NUMBER) if code.zero?
  code
end

def error_message

def error_message
  if failed?
    LDAP.err2string(error_code)
  else
    nil
  end
end

def failed?

def failed?
  not error_code.zero?
end

def find_paged_results_control(controls)

def find_paged_results_control(controls)
  controls.find do |control|
    control.oid == LDAP::LDAP_CONTROL_PAGEDRESULTS
  end
end

def paged_search(base, scope, filter, attributes, limit, page_size, &block)

def paged_search(base, scope, filter, attributes, limit, page_size, &block)
  cookie = ""
  critical = true
  loop do
    ber_string = LDAP::Control.encode(page_size, cookie)
    control = LDAP::Control.new(LDAP::LDAP_CONTROL_PAGEDRESULTS,
                                ber_string,
                                critical)
    search_ext(base,
               scope,
               filter,
               attributes,
               false,
               [control],
               nil,
               0,
               0,
               limit,
               &block)
    control = find_paged_results_control(@controls)
    break if control.nil?
    _estimated_result_set_size, cookie = control.decode
    break if cookie.empty?
  end
end

def search_full(options, &block)

def search_full(options, &block)
  base              = options[:base]
  scope             = options[:scope]
  filter            = options[:filter]
  attributes        = options[:attributes]
  limit             = options[:limit] || 0
  use_paged_results = options[:use_paged_results]
  page_size         = options[:page_size]
  if @@have_search_ext
    if use_paged_results
      paged_search(base,
                   scope,
                   filter,
                   attributes,
                   limit,
                   page_size,
                   &block)
    else
      search_ext(base,
                 scope,
                 filter,
                 attributes,
                 false,
                 nil,
                 nil,
                 0,
                 0,
                 limit,
                 &block)
    end
  else
    i = 0
    search(base, scope, filter, attributes) do |entry|
      i += 1
      block.call(entry)
      break if 0 < limit and limit <= i
    end
  end
end