### Home Classes Methods

### In Files

- lib/active_ldap/distinguished_name.rb

### Parent

Object

### Methods

- ::new
- #attribute_type_is_missing
- #attribute_value_is_missing
- #collect_pairs
- #found_unmatched_quotation
- #invalid_dn
- #name_component_is_missing
- #parse
- #rdn_is_missing
- #scan_attribute_type
- #scan_attribute_value
- #scan_not_quoted_attribute_value
- #scan_quoted_attribute_value
- #skip_attribute_type_and_value_separator

### Included Modules

- ActiveLdap::GetTextSupport

### Files

- USAGE

### Class/Module Index

Quicksearch

- ActiveLdap
- ActiveLdap::ActionController
- ActiveLdap::ActionController::LdapBenchmarking
- ActiveLdap::Acts
- ActiveLdap::Acts::Tree
- ActiveLdap::Acts::Tree::ClassMethods
- ActiveLdap::Adapter
- ActiveLdap::Adapter::Base
- ActiveLdap::Adapter::Jndi
- ActiveLdap::Adapter::JndiConnection
- ActiveLdap::Adapter::JndiConnection::ModifyRecord
- ActiveLdap::Adapter::JndiConnection::Scope
- ActiveLdap::Adapter::Ldap
- ActiveLdap::Adapter::Ldap::Method
- ActiveLdap::Adapter::Ldap::Method::Base
- ActiveLdap::Adapter::Ldap::Method::Plain
- ActiveLdap::Adapter::Ldap::Method::SSL
- ActiveLdap::Adapter::Ldap::Method::TLS
- ActiveLdap::Adapter::NetLdap
- ActiveLdap::Association
- ActiveLdap::Association::BelongsTo
- ActiveLdap::Association::BelongsToMany
- ActiveLdap::Association::Children
- ActiveLdap::Association::Collection
- ActiveLdap::Association::HasMany
- ActiveLdap::Association::HasManyUtils
- ActiveLdap::Association::HasManyWrap
- ActiveLdap::Association::Proxy
- ActiveLdap::Associations
- ActiveLdap::Associations::ClassMethods
- ActiveLdap::AttributeMethods
- ActiveLdap::AttributeMethods::BeforeTypeCast
- ActiveLdap::AttributeMethods::Dirty
- ActiveLdap::AttributeMethods::Query
- ActiveLdap::AttributeMethods::Read
- ActiveLdap::AttributeMethods::Write
- ActiveLdap::Attributes
- ActiveLdap::Attributes::ClassMethods
- ActiveLdap::Attributes::Normalizable
- ActiveLdap::Callbacks
- ActiveLdap::Callbacks::ClassMethods
- ActiveLdap::Command
- ActiveLdap::Compatible
- ActiveLdap::Configuration
- ActiveLdap::Configuration::ClassMethods
- ActiveLdap::Connection
- ActiveLdap::Connection::ClassMethods
- ActiveLdap::DN
- ActiveLdap::DistinguishedName
- ActiveLdap::DistinguishedName::Parser
- ActiveLdap::Entry
- ActiveLdap::EntryAttribute
- ActiveLdap::Escape
- ActiveLdap::Generators
- ActiveLdap::Generators::ModelGenerator
- ActiveLdap::Generators::ScaffoldGenerator
- ActiveLdap::GetText
- ActiveLdap::GetText::Parser
- ActiveLdap::GetTextSupport
- ActiveLdap::Helper
- ActiveLdap::HumanReadable
- ActiveLdap::HumanReadable::ClassMethods
- ActiveLdap::LDIF
- ActiveLdap::LdapError
- ActiveLdap::Ldif
- ActiveLdap::Ldif::AddRecord
- ActiveLdap::Ldif::Attribute
- ActiveLdap::Ldif::Attributes
- ActiveLdap::Ldif::ChangeRecord
- ActiveLdap::Ldif::ChangeRecord::Control
- ActiveLdap::Ldif::ContentRecord
- ActiveLdap::Ldif::DeleteRecord
- ActiveLdap::Ldif::ModifyDNRecord
- ActiveLdap::Ldif::ModifyNameRecord
- ActiveLdap::Ldif::ModifyRDNRecord
- ActiveLdap::Ldif::ModifyRecord
- ActiveLdap::Ldif::ModifyRecord::AddOperation
- ActiveLdap::Ldif::ModifyRecord::DeleteOperation
- ActiveLdap::Ldif::ModifyRecord::Operation
- ActiveLdap::Ldif::ModifyRecord::ReplaceOperation
- ActiveLdap::Ldif::Parser
- ActiveLdap::Ldif::Record
- ActiveLdap::Ldif::Scanner
- ActiveLdap::LogSubscriber
- ActiveLdap::ObjectClass
- ActiveLdap::ObjectClass::ClassMethods
- ActiveLdap::Operations
- ActiveLdap::Operations::ClassOnlyDelete
- ActiveLdap::Operations::ClassOnlyUpdate
- ActiveLdap::Operations::Common
- ActiveLdap::Operations::Delete
- ActiveLdap::Operations::Find
- ActiveLdap::Operations::LDIF
- ActiveLdap::Operations::LDIF::AddRecordLoadable
- ActiveLdap::Operations::LDIF::ContentRecordLoadable
- ActiveLdap::Operations::LDIF::DeleteRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyNameRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::AddOperationModifiable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::DeleteOperationModifiable
- ActiveLdap::Operations::LDIF::ModifyRecordLoadable::ReplaceOperationModifiable
- ActiveLdap::Operations::Update
- ActiveLdap::Persistence
- ActiveLdap::Populate
- ActiveLdap::Railtie
- ActiveLdap::Railties
- ActiveLdap::Railties::ControllerRuntime
- ActiveLdap::Railties::ControllerRuntime::ClassMethods
- ActiveLdap::Schema
- ActiveLdap::Schema::Attribute
- ActiveLdap::Schema::Entry
- ActiveLdap::Schema::ObjectClass
- ActiveLdap::Schema::Syntax
- ActiveLdap::Schema::Syntaxes
- ActiveLdap::Schema::Syntaxes::Base
- ActiveLdap::Schema::Syntaxes::BitString
- ActiveLdap::Schema::Syntaxes::Boolean
- ActiveLdap::Schema::Syntaxes::CountryString
- ActiveLdap::Schema::Syntaxes::DirectoryString
- ActiveLdap::Schema::Syntaxes::DistinguishedName
- ActiveLdap::Schema::Syntaxes::GeneralizedTime
- ActiveLdap::Schema::Syntaxes::Integer
- ActiveLdap::Schema::Syntaxes::JPEG
- ActiveLdap::Schema::Syntaxes::NameAndOptionalUID
- ActiveLdap::Schema::Syntaxes::NumericString
- ActiveLdap::Schema::Syntaxes::OID
- ActiveLdap::Schema::Syntaxes::ObjectSecurityDescriptor
- ActiveLdap::Schema::Syntaxes::OctetString
- ActiveLdap::Schema::Syntaxes::OtherMailbox
- ActiveLdap::Schema::Syntaxes::PostalAddress
- ActiveLdap::Schema::Syntaxes::PrintableString
- ActiveLdap::Schema::Syntaxes::TelephoneNumber
- ActiveLdap::UserPassword
- ActiveLdap::UserPassword::Salt
- ActiveLdap::Validations
- ActiveLdap::XML
- ActiveLdap::Xml
- ActiveLdap::Xml::Serializer
- LDAP
- LDAP::Conn
- LDAP::Mod
- Net
- Net::LDAP
- Net::LDAP::Entry
- ActionView
- ActionView::Base
- URI
- URI::LDAPS
- Object
- Timeout

No matching classes.

# ActiveLdap::DistinguishedName::Parser

### Constants

ATTRIBUTE_TYPE_RE
HEX_PAIR
HEX_STRING_RE
PAIR_RE
STRING_CHARS_RE

### Attributes

dn[R]

### Public Class Methods

new(source) click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 11
    def initialize(source)
      @dn = nil
      source = source.to_s if source.is_a?(DN)
      unless source.is_a?(String)
        raise DistinguishedNameInputInvalid.new(source)
      end
      @source = source
    end

### Public Instance Methods

parse() click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 20
    def parse
      return @dn if @dn

      rdns = []
      scanner = StringScanner.new(@source)

      scanner.scan(/\s*/)
      raise rdn_is_missing if scanner.scan(/\s*\+\s*/)
      raise name_component_is_missing if scanner.scan(/\s*,\s*/)

      rdn = {}
      until scanner.eos?
        type = scan_attribute_type(scanner)
        skip_attribute_type_and_value_separator(scanner)
        value = scan_attribute_value(scanner)
        rdn[type] = value
        if scanner.scan(/\s*\+\s*/)
          raise rdn_is_missing if scanner.eos?
        elsif scanner.scan(/\s*\,\s*/)
          rdns << rdn
          rdn = {}
          raise name_component_is_missing if scanner.eos?
        else
          scanner.scan(/\s*/)
          rdns << rdn if scanner.eos?
        end
      end

      @dn = DN.new(*rdns)
      @dn
    end

### Private Instance Methods

attribute_type_is_missing() click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 143
    def attribute_type_is_missing
      invalid_dn(_("attribute type is missing"))
    end

attribute_value_is_missing() click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 147
    def attribute_value_is_missing
      invalid_dn(_("attribute value is missing"))
    end

collect_pairs(scanner) click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 118
    def collect_pairs(scanner)
      result = ""
      while scanner.scan(PAIR_RE)
        if scanner[2]
          result << [scanner[2].hex].pack("C*")
        else
          result << scanner[1]
        end
      end
      result.force_encoding("utf-8") if result.respond_to?(:force_encoding)
      result
    end

found_unmatched_quotation() click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 151
    def found_unmatched_quotation
      invalid_dn(_("found unmatched quotation"))
    end

invalid_dn(reason) click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 131
    def invalid_dn(reason)
      DistinguishedNameInvalid.new(@source, reason)
    end

name_component_is_missing() click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 135
    def name_component_is_missing
      invalid_dn(_("name component is missing"))
    end

rdn_is_missing() click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 139
    def rdn_is_missing
      invalid_dn(_("relative distinguished name (RDN) is missing"))
    end

scan_attribute_type(scanner) click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 54
    def scan_attribute_type(scanner)
      raise attribute_type_is_missing unless scanner.scan(ATTRIBUTE_TYPE_RE)
      scanner[1]
    end

scan_attribute_value(scanner) click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 67
    def scan_attribute_value(scanner)
      if scanner.scan(HEX_STRING_RE)
        value = scanner[1].scan(/../).collect do |hex_pair|
          hex_pair.hex
        end.pack("C*")
      elsif scanner.scan(/\"/)
        value = scan_quoted_attribute_value(scanner)
      else
        value = scan_not_quoted_attribute_value(scanner)
      end
      raise attribute_value_is_missing if value.blank?

      value
    end

scan_not_quoted_attribute_value(scanner) click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 99
    def scan_not_quoted_attribute_value(scanner)
      result = ""
      until scanner.eos?
        prev_size = result.size
        pairs = collect_pairs(scanner)
        strings = scanner.scan(STRING_CHARS_RE)
        result << pairs if !pairs.nil? and !pairs.empty?
        unless strings.nil?
          if scanner.peek(1) == ","
            result << strings.rstrip
          else
            result << strings
          end
        end
        break if prev_size == result.size
      end
      result
    end

scan_quoted_attribute_value(scanner) click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 82
    def scan_quoted_attribute_value(scanner)
      result = ""
      until scanner.scan(/\"/)
        scanner.scan(/([^\\\"]*)/)
        quoted_strings = scanner[1]
        pairs = collect_pairs(scanner)

        if scanner.eos? or (quoted_strings.empty? and pairs.empty?)
          raise found_unmatched_quotation
        end

        result << quoted_strings
        result << pairs
      end
      result
    end

skip_attribute_type_and_value_separator(scanner) click to toggle source

    # File lib/active_ldap/distinguished_name.rb, line 59
    def skip_attribute_type_and_value_separator(scanner)
      raise attribute_value_is_missing unless scanner.scan(/\s*=\s*/)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.