[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Special characters in attribute values



Does this means that you use this script to make the conversion before storing the info in the server? But how does the LDAP server know that the info is encoded? Thanks,
Alejandra
At 13:56 12.11.2001 +0100, you wrote:
Am Mon, Nov 12, 2001 at 01:31:34PM +0100 schrieb Alejandra Moreno:
> utf8 encoding is a syntax type? What's its OID? Thanks.
It's no syntax type - encoding, compareable to base64 - for encoding ascii.
ldap servers encode such ascii-strings (umlauts) into utf8.
I use a perl code-snippet here, which does the conversion for me:
# ======================================================================
sub ansi2UTF($){
my $string = shift;
my @chars = split(//, $string);
my $lowByte;
my $highByte;
my $i;
for ($i=0;$i<=$#chars;$i++){
my $assciCode = ord($chars[$i]);
if ($assciCode > 127){
$lowByte = $assciCode & 192;
$lowByte = $lowByte >> 6;
$lowByte = $lowByte & 3;
$lowByte += 192;
$highByte = $assciCode & 63;
$highByte += 128;
splice(@chars, $i, 1, (chr($lowByte), chr($highByte)));
$i++;
}
}
return(join('', @chars));
}
# ======================================================================
sub utf2ANSI($){
my $string = shift;
my @chars = split(//, $string);
my $i =0;
for ($i=0;$i<=$#chars;$i++){
my $byteCounter =0;
my $assciCode = ord($chars[$i]);
if ($assciCode > 127){
# Wieviele Bytes werden gebraucht
while ( ($assciCode & 128) == 128){
$byteCounter++;
$assciCode = $assciCode << 1;
}


#Solange Shiften, bis der erste 1 vorne steht
while ( ($assciCode & 128) != 128){
$assciCode = $assciCode << 1;
}
# Alle folgenden Bytes
my $j;
my $nextval;
for($j=1;$j<$byteCounter;$j++){
$nextval = ord($chars[$i+$j]) & 63;
$assciCode += $nextval;
splice(@chars, $i+$j, 1);
}
}
if ($byteCounter > 2){
$chars[$i] = '?';
}else{
$chars[$i] = chr($assciCode);
}
}
return(join('', @chars));
}
# ======================================================================
good luck and
best regards,
Sven
--
Sven Giersig |
mailto: smg@weird.dnsalias.org | Unix Inter-Networking
mobile: +49-172-8049514 | Directory Services
https://weird.dnsalias.org/~smg |
______________________________________________________________________
Alejandra Moreno Espinar
at rete ag
mailto:alejandra.moreno@atrete.ch, http://www.atrete.ch
snail mail: Oberdorfstrasse 2, P.O. Box 674, 8024 Zurich, Switzerland
voice: +41-1-266 55 55, direct: +41-1-266 55 91, fax: +41-1-266 55 88
_____________________________________________________________________




______________________________________________________________________ Alejandra Moreno Espinar at rete ag

mailto:alejandra.moreno@atrete.ch, http://www.atrete.ch
snail mail: Oberdorfstrasse 2, P.O. Box 674, 8024 Zurich, Switzerland
voice: +41-1-266 55 55, direct: +41-1-266 55 91, fax: +41-1-266 55 88
_____________________________________________________________________