#!/usr/bin/perl use utf8; require "AllSubs.pl"; &DoStartup; if(defined($Help)) { print << "EOF"; ToASCII.pl, version 3.0, by Paul Hoffman This program is provided with no warranty and may not work as expected. You may freely distribute this program. Program to perform the steps in ToASCII in RFC 3490. The input is UTF-8; the output is ASCII. Using the '-writefiles' option causes the STDOUT to be written to 'thestdout' and the STDERR to be written to 'thestderr'. This is useful when calling from CGIs. Using the '-dounass' optiong causes the program to check against the unassigned character list when checking for prohibited characters. Without this option, the check is not done. EOF exit; } &DebugOut("ToASCII Step 1 (Check for all-ASCII)\n"); $IsAllASCII = &CheckAllASCII($InputPart); if($IsAllASCII) { $NormalizedOutput = $InputPart; &DebugOut(" Was all ASCII, skipping to step 3\n"); } else { &DebugOut("ToASCII Step 2 (Nameprep)\n"); $NormalizedOutput = &DoNamePrep($InputPart); unless($NameprepWasOK) { &DieOut("***ToASCII failing in step 2 because Nameprep aborted\n"); } } &DebugOut("ToASCII Step 3a (Check for non-LDH ASCII)\n"); if(&CheckNonLDH($NormalizedOutput)) { &DieOut(" ***ToASCII failing in Step 3a\n"); } &DebugOut("ToASCII Step 3b (Check for leading or trailing hyphen)\n"); if(substr($NormalizedOutput, 0, 1) eq '-') { &DieOut(" ***ToASCII failing in Step 3b for leading hyphen)\n"); } if(substr($NormalizedOutput, -1, 1) eq '-') { &DieOut(" ***ToASCII failing in Step 3b for trailing hyphen)\n"); } &DebugOut("ToASCII Step 4 (Check for all-ASCII)\n"); $IsAllASCII = &CheckAllASCII($NormalizedOutput); if($IsAllASCII) { $FullLabel = $NormalizedOutput; } else { &DebugOut("ToASCII Step 5 (Check for lack of ACE prefix)\n"); if(lc(substr($NormalizedOutput, 0, 4)) eq $ACEPrefix) { &DieOut(" ***ToASCII failing in Step 5 for having the prefix)\n"); } &DebugOut("ToASCII Step 6 (Encode with Punycode)\n"); open(ACETEMP, ">:utf8", "$HBase/thestdace") or &DieOut("Could not write thestdace holder"); print ACETEMP $NormalizedOutput; close(ACETEMP); $PunycodeEncodeCmd = "$HBase/UnicodeConvert.pl -infmt utf8 " . " -outfmt punycode -errtmp <$HBase/thestdace"; $PunycodeOut = `$PunycodeEncodeCmd`; if($PunycodeOut eq '') { $ErrMsg = `cat $HBase/thestdunicodedie`; &DieOut("Fatal problem doing Punycode encoding:\n$ErrMsg\n"); } else { &DebugOut(" After step 6, the label is $PunycodeOut\n"); } &DebugOut("ToASCII Step 7 (Prepend ACE prefix)\n"); $FullLabel = "$ACEPrefix$PunycodeOut"; &DebugOut(" After step 7, the label is $FullLabel\n"); } &DebugOut("ToASCII Step 8 (Check label length)\n"); if(length($FullLabel) == 0) { &DieOut(" ***ToASCII failing because label has length 0\n"); } elsif(length($FullLabel) > 63) { &DieOut(" ***ToASCII failing because label has length >63\n");; } &DebugOut(" After step 8, the label is $FullLabel\n"); print REALOUT $FullLabel; exit;