From: Norbert K. <nor...@da...> - 2002-04-23 09:33:47
|
--On Freitag, 19. April 2002 08:43 +0100 Graham Barr <gb...@po...> wrote: > Whats wrong with the subs in Net::LDAP::Utils ? ldap_explode_dn does not unescape escaped characters, e.g. the DN 'CN=3D\= #John Smith\ ' becomes $VAR1 =3D { 'CN' =3D> '\\#John Smith\\20' }; instad of $VAR1 =3D { 'CN' =3D> '#John Smith ' }; likewise 'CN=3DLu\C4\8Di\C4\87' becomes $VAR1 =3D { 'CN' =3D> 'Lu\\c4\\8di\\c4\\87' }; instead of $VAR1 =3D { 'CN' =3D> 'Lucic' }; We needed the unescaped variants to display DNs nicely in our webgateway. They are also needed, if an "exploded DN" is to be converted back to a pl= ain string. This "folding" can be done by canonical_dn. It now also takes a reference to an array as returned by ldap_explode_dn in addition to plain strings. This way, "move upwards" buttons can be implemented easily by taking slices of arrays returned by ldap_explode_dn. Additionally the behavior of the two functions concerning casefolding, escaping and RDN ordering can be controlled by parameters: FUNCTIONS canonical_dn ( DN [ , OPTIONS ] ) Returns the given DN in a canonical form. Returns undef if DN is not a valid Distinguished Name. (Note: The empty string "" is a valid DN.) DN can either be a string or a reference to an array of hashes as returned by ldap_explode_dn. It performs the following operations on the given DN: o Removes the leading 'OID.' characters if the type is an OID instead of a name. o Escapes all RFC 2253 special characters (",", "+", """, "\", "<", ">", ";", "#", "=3D", " "), slashes ("/"), and any other character where the ASCII code is <32 as \hexpair. o Converts all leading and trailing spaces in values to be \20. o If an RDN contains multiple parts, the parts are re-ordered so that the attribute type names are in alphabetical order. OPTIONS is a list of name/value pairs, valid options are: binary This argument is a reference to a list of attribute type names . Values of these attribute types will be escaped as #(hexpair)*. casefold Controls case folding of attribute type names. Attribute values are not affected by this option. The default is to uppercase. Valid values are: lower Lowercase attribute type names. upper Uppercase attribute type names. This is the default. none Do not change attribute type names. mbcescape If TRUE, multi byte characters will be escaped as \(hexpair){2,*} reverse If TRUE, the RDN sequence is reversed. separator Separator to use between RDNs. Defaults to comma (','). ldap_explode_dn ( DN [ , OPTIONS ] ) Explodes the given DN into an array of hashes. Returns undef if DN is not a valid Distinguished Name. It also performs the following operations on the given DN: o Unescape "\" followed by ",", "+", """, "\", "<", ">", ";", "#", "=3D", " ", or a hexpair and and strings beginning with "#". o Removes the leading OID. characters if the type is an OID instead of a name. OPTIONS is a list of name/value pairs, valid options are: casefold Controls case folding of attribute types names. Attribute values are not affected by this option. The default is to uppercase. Valid values are: lower Lowercase attribute types names. upper Uppercase attribute type names. This is the default. none Do not change attribute type names. -- Norbert Klasen, Dipl.-Inform. DAASI International GmbH phone: +49 7071 29 70336 Wilhelmstr. 106 fax: +49 7071 29 5114 72074 T=FCbingen email: nor...@da... Germany web: http://www.daasi.de |