Hi list, as announced in my post from 28. October (see below) I have committed a patch to perl-ldap's SVN that allows to get attribute values from LDAP directories and LDIF files correctly encoded as Perl strings.
This is especially interesting for people who have strings with non-ASCII values in their directories. The patch add an additional attribute called binary to Net::LDAP's new() constructor and search() method that contains a regular expression which matches all attribute names that are not to be converted to Perl strings. If the binary attribute is not given at all perl-ldap's behaviour is the same as before. If it is given in new() it is automatically inherited by each search() unless specified differently there. Here is an example: === 8< snip >8 === use Net::LDAP; # un-comment ithis if you have your locale set to UTF-8 #binmode(STDOUT, ":encoding(utf8)"); my $ldap = Net::LDAP->new('localhost', version => 3); $ldap->bind('cn=Administrator', password => '****'); my $search = $ldap->search(base => 'ou=EIS,o=Dir4E', filter => '(sn=*)', attrs => [ qw/sn givenName mail/ ], binary => qr/;binary|^jpegPhoto/io ); print $search->error() if ($search->code()); while (my $entry = $search->shift_entry()) { print lc($entry->get_value('sn')), " ", lc($entry->get_value('givenName)), "\n"; } === 8< snip >8 === It is currently only lightly tested (but hey, this is what SVN is for ;-) The adventourous of you out there, please test and give me feedback. Have fun with it Peter On Friday, 28. October 2005 09:19, Peter Marschall wrote: > I am trying to get non-ACII characters in attributes/objects that I get > back from directories using Net::LDAP correctly encoded in Perl-unicode > (I.e. so that uc("Hägar") results in "HÄGAR" and not in "HäGAR" or even > errors) > Unfortunately I have not found any solution that worked as I wanted. > > Then I tried to take another route: > Why not let Convert::ASN1 do the dirty work of upgrading the UTF8 strings > to Perl-unicode. For the other direction (sending Perl-uncode chars to LDAP > directories) it already does it. > > Thinking about it a bit longer I came to the conclusion that Convert::ASN1 > might be the wrong place to do it since there may be some discrepancies > between the ASN1 encoding and the programmers' needs (i.e. sometimes one > may need to have the raw byte-value of an attribute) > And besides, this change deep in Convert::ASN1 might break applications > that use Net::LDAP. > > So I thought about adding a parameter 'binary' to Net::LDAP->new() and > Net::LDIF->new() that contains a list / pattern of all the attribute names > whose values should NOT be upgraded to Perl-unicode. > Then, whenever a search is performed or an LDIF file is read > Net::LDAP::Search and Net::LDIF take care of upgrading the values of the > attributes that are not in the binary list to Perl-unicode. > (I chose the negative selection 'binary' to get the list shorter, because > IMHO most anttributes in an LDAP directory are text) > > To keep compatibility with existing installations, the presence of > the 'binary' attribute is required for Net::LDAP::Search / Net::LDIF to > behave the way described above. > > What do you think about it ? > > Or did I completely miss something very basic and all this stuff above is > completely unnecessary ? -- Peter Marschall eMail: [EMAIL PROTECTED]