1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Mozilla Communicator client code, released
15 * March 31, 1998.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-1999
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37 /*
38 * Copyright (c) 1995 Regents of the University of Michigan.
39 * All rights reserved.
40 */
41 /*
42 * charset.c
43 */
44
45 #include "ldap-int.h"
46
47 #ifdef STR_TRANSLATION
48
49 void
ldap_set_string_translators(LDAP * ld,BERTranslateProc encode_proc,BERTranslateProc decode_proc)50 ldap_set_string_translators( LDAP *ld, BERTranslateProc encode_proc,
51 BERTranslateProc decode_proc )
52 {
53 if ( ld == NULL ) {
54 if ( !nsldapi_initialized ) {
55 nsldapi_initialize_defaults();
56 }
57 ld = &nsldapi_ld_defaults;
58 }
59
60 if ( NSLDAPI_VALID_LDAP_POINTER( ld )) {
61 ld->ld_lber_encode_translate_proc = encode_proc;
62 ld->ld_lber_decode_translate_proc = decode_proc;
63 }
64 }
65
66
67 void
ldap_enable_translation(LDAP * ld,LDAPMessage * entry,int enable)68 ldap_enable_translation( LDAP *ld, LDAPMessage *entry, int enable )
69 {
70 char *optionsp;
71
72 if ( ld == NULL ) {
73 if ( !nsldapi_initialized ) {
74 nsldapi_initialize_defaults();
75 }
76 ld = &nsldapi_ld_defaults;
77 }
78
79 optionsp = ( entry == NULLMSG ) ? &ld->ld_lberoptions :
80 &entry->lm_ber->ber_options;
81
82 if ( enable ) {
83 *optionsp |= LBER_OPT_TRANSLATE_STRINGS;
84 } else {
85 *optionsp &= ~LBER_OPT_TRANSLATE_STRINGS;
86 }
87 }
88
89
90 int
ldap_translate_from_t61(LDAP * ld,char ** bufp,unsigned long * lenp,int free_input)91 ldap_translate_from_t61( LDAP *ld, char **bufp, unsigned long *lenp,
92 int free_input )
93 {
94 if ( ld->ld_lber_decode_translate_proc == NULL ) {
95 return( LDAP_SUCCESS );
96 }
97
98 return( (*ld->ld_lber_decode_translate_proc)( bufp, lenp, free_input ));
99 }
100
101
102 int
ldap_translate_to_t61(LDAP * ld,char ** bufp,unsigned long * lenp,int free_input)103 ldap_translate_to_t61( LDAP *ld, char **bufp, unsigned long *lenp,
104 int free_input )
105 {
106 if ( ld->ld_lber_encode_translate_proc == NULL ) {
107 return( LDAP_SUCCESS );
108 }
109
110 return( (*ld->ld_lber_encode_translate_proc)( bufp, lenp, free_input ));
111 }
112
113
114 /*
115 ** Character translation routine notes:
116 *
117 * On entry: bufp points to a "string" to be converted (not necessarily
118 * zero-terminated) and buflenp points to the length of the buffer.
119 *
120 * On exit: bufp should point to a malloc'd result. If free_input is
121 * non-zero then the original bufp will be freed. *buflenp should be
122 * set to the new length. Zero bytes in the input buffer must be left
123 * as zero bytes.
124 *
125 * Return values: any ldap error code (LDAP_SUCCESS if all goes well).
126 */
127
128
129 #ifdef LDAP_CHARSET_8859
130
131 #if LDAP_CHARSET_8859 == 88591
132 #define ISO_8859 1
133 #elif LDAP_CHARSET_8859 == 88592
134 #define ISO_8859 2
135 #elif LDAP_CHARSET_8859 == 88593
136 #define ISO_8859 3
137 #elif LDAP_CHARSET_8859 == 88594
138 #define ISO_8859 4
139 #elif LDAP_CHARSET_8859 == 88595
140 #define ISO_8859 5
141 #elif LDAP_CHARSET_8859 == 88596
142 #define ISO_8859 6
143 #elif LDAP_CHARSET_8859 == 88597
144 #define ISO_8859 7
145 #elif LDAP_CHARSET_8859 == 88598
146 #define ISO_8859 8
147 #elif LDAP_CHARSET_8859 == 88599
148 #define ISO_8859 9
149 #elif LDAP_CHARSET_8859 == 885910
150 #define ISO_8859 10
151 #else
152 #define ISO_8859 0
153 #endif
154
155 /*
156 * the following ISO_8859 to/afrom T.61 character set translation code is
157 * based on the code found in Enrique Silvestre Mora's iso-t61.c, found
158 * as part of this package:
159 * ftp://pereiii.uji.es/pub/uji-ftp/unix/ldap/iso-t61.translation.tar.Z
160 * Enrique is now (10/95) at this address: enrique.silvestre@uv.es
161 *
162 * changes made by mcs@umich.edu 12 October 1995:
163 * Change calling conventions of iso8859_t61() and t61_iso8859() to
164 * match libldap conventions; rename to ldap_8859_to_t61() and
165 * ldap_t61_to_8859().
166 * Change conversion routines to deal with non-zero terminated strings.
167 * ANSI-ize functions and include prototypes.
168 */
169
170 /* iso-t61.c - ISO-T61 translation routines (version: 0.2.1, July-1994) */
171 /*
172 * Copyright (c) 1994 Enrique Silvestre Mora, Universitat Jaume I, Spain.
173 * All rights reserved.
174 *
175 * Redistribution and use in source and binary forms are permitted
176 * provided that this notice is preserved and that due credit is given
177 * to the Universitat Jaume I. The name of the University
178 * may not be used to endorse or promote products derived from this
179 * software without specific prior written permission. This software
180 * is provided ``as is'' without express or implied warranty.
181 */
182
183
184 #include <stdio.h>
185 #include <stdlib.h>
186 #include <string.h>
187
188 /* Character set used: ISO 8859-1, ISO 8859-2, ISO 8859-3, ... */
189 /* #define ISO_8859 1 */
190
191 #ifndef ISO_8859
192 # define ISO_8859 0
193 #endif
194
195 typedef unsigned char Byte;
196 typedef struct { Byte a, b; } Couple;
197
198 #ifdef NEEDPROTOS
199 static Byte *c_to_hh( Byte *o, Byte c );
200 static Byte *c_to_cc( Byte *o, Couple *cc, Byte c );
201 static int hh_to_c( Byte *h );
202 static Byte *cc_to_t61( Byte *o, Byte *s );
203 #else /* NEEDPROTOS */
204 static Byte *c_to_hh();
205 static Byte *c_to_cc();
206 static int hh_to_c();
207 static Byte *cc_to_t61();
208 #endif /* NEEDPROTOS */
209
210 /*
211 Character choosed as base in diacritics alone: NO-BREAK SPACE.
212 (The standard say it must be a blank space, 0x20.)
213 */
214 #define ALONE 0xA0
215
216 static Couple diacritic[16] = {
217 #if (ISO_8859 == 1) || (ISO_8859 == 9)
218 {0,0}, {'`',0}, {0xb4,0}, {'^',0},
219 {'~',0}, {0xaf,0}, {'(',ALONE}, {'.',ALONE},
220 {0xa8,0}, {0,0}, {'0',ALONE}, {0xb8,0},
221 {0,0}, {'"',ALONE}, {';',ALONE}, {'<',ALONE},
222 #elif (ISO_8859 == 2)
223 {0,0}, {'`',0}, {0xb4,0}, {'^',0},
224 {'~',0}, {'-',ALONE}, {0xa2,0}, {0xff,0},
225 {0xa8,0}, {0,0}, {'0',ALONE}, {0xb8,0},
226 {0,0}, {0xbd,0}, {0xb2,0}, {0xb7,0}
227 #elif (ISO_8859 == 3)
228 {0,0}, {'`',0}, {0xb4,0}, {'^',0},
229 {'~',0}, {'-',ALONE}, {0xa2,0}, {0xff,0},
230 {0xa8,0}, {0,0}, {'0',ALONE}, {0xb8,0},
231 {0,0}, {'"',ALONE}, {';',ALONE}, {'<',ALONE}
232 #elif (ISO_8859 == 4)
233 {0,0}, {'`',0}, {0xb4,0}, {'^',0},
234 {'~',0}, {0xaf,0}, {'(',ALONE}, {0xff,0},
235 {0xa8,0}, {0,0}, {'0',ALONE}, {0xb8,0},
236 {0,0}, {'"',ALONE}, {0xb2,0}, {0xb7,0}
237 #else
238 {0,0}, {'`',0}, {'\'',ALONE}, {'^',0},
239 {'~',0}, {'-',ALONE}, {'(',ALONE}, {'.',ALONE},
240 {':',ALONE}, {0,0}, {'0',ALONE}, {',',ALONE},
241 {0,0}, {'"',ALONE}, {';',ALONE}, {'<',ALONE}
242 #endif
243 };
244
245 /*
246 --- T.61 (T.51) letters with diacritics: conversion to ISO 8859-n -----
247 A, C, D, E, G, H, I, J, K,
248 L, N, O, R, S, T, U, W, Y, Z.
249 -----------------------------------------------------------------------
250 */
251 static int letter_w_diacritic[16][38] = {
252 #if (ISO_8859 == 1)
253 0, 0, 0, 0, 0, 0, 0, 0, 0,
254 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
255 0, 0, 0, 0, 0, 0, 0, 0, 0,
256 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
257 0xc0,0, 0, 0xc8,0, 0, 0xcc,0, 0,
258 0, 0, 0xd2,0, 0, 0, 0xd9,0, 0, 0,
259 0xe0,0, 0, 0xe8,0, 0, 0xec,0, 0,
260 0, 0, 0xf2,0, 0, 0, 0xf9,0, 0, 0,
261 0xc1,-1, 0, 0xc9,0, 0, 0xcd,0, 0,
262 -1, -1, 0xd3,-1, -1, 0, 0xda,0, 0xdd,-1,
263 0xe1,-1, 0, 0xe9,0, 0, 0xed,0, 0,
264 -1, -1, 0xf3,-1, -1, 0, 0xfa,0, 0xfd,-1,
265 0xc2,-1, 0, 0xca,-1, -1, 0xce,-1, 0,
266 0, 0, 0xd4,0, -1, 0, 0xdb,-1, -1, 0,
267 0xe2,-1, 0, 0xea,-1, -1, 0xee,-1, 0,
268 0, 0, 0xf4,0, -1, 0, 0xfb,-1, -1, 0,
269 0xc3,0, 0, 0, 0, 0, -1, 0, 0,
270 0, 0xd1,0xd5,0, 0, 0, -1, 0, 0, 0,
271 0xe3,0, 0, 0, 0, 0, -1, 0, 0,
272 0, 0xf1,0xf5,0, 0, 0, -1, 0, 0, 0,
273 -1, 0, 0, -1,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
306 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
307 0, 0, 0, 0, 0, 0, 0, 0, 0,
308 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
309 -1, 0, 0, -1, 0, 0, -1, 0, 0,
310 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
311 -1, 0, 0, -1, 0, 0, -1, 0, 0,
312 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
313 0, -1, -1, -1, 0, 0, 0, 0, 0,
314 -1, -1, 0, -1, -1, -1, 0, 0, 0, -1,
315 0, -1, -1, -1, 0, 0, 0, 0, 0,
316 -1, -1, 0, -1, -1, -1, 0, 0, 0, -1
317 #elif (ISO_8859 == 2)
318 0, 0, 0, 0, 0, 0, 0, 0, 0,
319 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
320 0, 0, 0, 0, 0, 0, 0, 0, 0,
321 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
322 -1, 0, 0, -1, 0, 0, -1, 0, 0,
323 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
324 -1, 0, 0, -1, 0, 0, -1, 0, 0,
325 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
326 0xc1,0xc6,0, 0xc9,0, 0, 0xcd,0, 0,
327 0xc5,0xd1,0xd3,0xc0,0xa6,0, 0xda,0, 0xdd,0xac,
328 0xe1,0xe6,0, 0xe9,0, 0, 0xed,0, 0,
329 0xe5,0xf1,0xf3,0xe0,0xb6,0, 0xfa,0, 0xfd,0xbc,
330 0xc2,-1, 0, -1, -1, -1, 0xce,-1, 0,
331 0, 0, 0xd4,0, -1, 0, -1, -1, -1, 0,
332 0xe2,-1, 0, -1, -1, -1, 0xee,-1, 0,
333 0, 0, 0xf4,0, -1, 0, -1, -1, -1, 0,
334 -1, 0, 0, 0, 0, 0, -1, 0, 0,
335 0, -1, -1, 0, 0, 0, -1, 0, 0, 0,
336 -1, 0, 0, 0, 0, 0, -1, 0, 0,
337 0, -1, -1, 0, 0, 0, -1,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
431 0, 0, 0, 0, 0, 0, 0, 0, 0,
432 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
433 0, 0, 0, 0, 0, 0, 0, 0, 0,
434 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
435 0, 0, 0, 0, 0, 0, 0, 0, 0,
436 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
437 0, 0, 0, 0, 0, 0, 0, 0, 0,
438 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
439 -1, 0, 0, -1, 0, 0, -1, 0, 0,
440 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
441 -1, 0, 0, -1, 0, 0, -1, 0, 0,
442 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
443 0, -1, -1, -1, 0, 0, 0, 0, 0,
444 -1, -1, 0, -1, -1, -1, 0, 0, 0, -1,
445 0, -1, -1, -1, 0, 0, 0, 0, 0,
446 -1, -1, 0, -1, -1, -1, 0, 0, 0, -1
447 #elif (ISO_8859 == 4)
448 0, 0, 0, 0, 0, 0, 0, 0, 0,
449 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
450 0, 0, 0, 0, 0, 0, 0, 0, 0,
451 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
452 -1, 0, 0, -1, 0, 0, -1, 0, 0,
453 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
454 -1, 0, 0, -1, 0, 0, -1, 0, 0,
455 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
456 0xc1,-1, 0, 0xc9,0, 0, 0xcd,0, 0,
457 -1, -1, -1, -1, -1, 0, 0xda,0, -1, -1,
458 0xe1,-1, 0, 0xe9,0, 0, 0xed,0, 0,
459 -1, -1, -1, -1, -1, 0, 0xfa,0, -1, -1,
460 0xc2,-1, 0, -1, -1, -1, 0xce,-1, 0,
461 0, 0, 0xd4,0, -1, 0, 0xdb,-1, -1, 0,
462 0xe2,-1, 0, -1, -1, -1, 0xee,-1, 0,
463 0, 0, 0xf4,0, -1, 0, 0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c7,0, 0, -1, 0, 0, 0, -1,
558 -1, -1, 0, -1, 0xde,-1, 0, 0, 0, 0,
559 0, 0xe7,0, 0, -1, 0, 0, 0, -1,
560 -1, -1, 0, -1, 0xfe,-1, 0, 0, 0, 0,
561 0, 0, 0, 0, 0, 0, 0, 0, 0,
562 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
563 0, 0, 0, 0, 0, 0, 0, 0, 0,
564 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
565 0, 0, 0, 0, 0, 0, 0, 0, 0,
566 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
567 0, 0, 0, 0, 0, 0, 0, 0, 0,
568 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
569 -1, 0, 0, -1, 0, 0, -1, 0, 0,
570 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
571 -1, 0, 0, 0xea,0, 0, -1, 0, 0,
572 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
573 0, -1, -1, -1, 0, 0, 0, 0, 0,
574 -1, -1, 0, -1, -1, -1, 0, 0, 0, -1,
575 0, -1, -1, -1, 0, 0, 0, 0, 0,
576 -1, -1, 0, -1, -1, -1, 0, 0, 0, -1
577 #elif (ISO_8859 == 10)
578 0, 0, 0, 0, 0, 0, 0, 0, 0,
579 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
580 0, 0, 0, 0, 0, 0, 0, 0, 0,
581 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
582 -1, 0, 0, -1, 0, 0, -1, 0, 0,
583 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
584 -1, 0, 0, -1, 0, 0, -1, 0, 0,
585 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
586 0xc1,-1, 0, 0xc9,0, 0, 0xcd,0, 0,
587 -1, -1, 0xd3,-1, -1, 0, 0xda,0, 0xdd,-1,
588 0xe1,-1, 0, 0xe9,0, 0, 0xed,0, 0,
589 -1, -1, 0xf3,-1, -1, 0, 0xfa,0,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0, 0, 0, 0, 0,
621 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
622 0, -1, 0, 0, 0xa3,0, 0, 0, 0xa6,
623 0xa8,0xd1,0, -1, -1, -1, 0, 0, 0, 0,
624 0, -1, 0, 0, 0xb3,0, 0, 0, 0xb6,
625 0xb8,0xf1,0, -1, -1, -1, 0, 0, 0, 0,
626 0, 0, 0, 0, 0, 0, 0, 0, 0,
627 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
628 0, 0, 0, 0, 0, 0, 0, 0, 0,
629 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
630 0, 0, 0, 0, 0, 0, 0, 0, 0,
631 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
632 0, 0, 0, 0, 0, 0, 0, 0, 0,
633 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
634 0xa1,0, 0, 0xca,0, 0, 0xc7,0, 0,
635 0, 0, 0, 0, 0, 0, 0xd9,0, 0, 0,
636 0xb1,0, 0, 0xea,0, 0, 0xe7,0, 0,
637 0, 0, 0, 0, 0, 0, 0xf9,0, 0, 0,
638 0, 0xc8,-1, -1, 0, 0, 0, 0, 0,
639 -1, -1, 0, -1, 0xaa,-1, 0, 0, 0, 0xac,
640 0, 0xe8,-1, -1, 0, 0, 0, 0, 0,
641 -1, -1, 0, -1, 0xba,-1, 0, 0, 0, 0xbc
642 #else
643 0, 0, 0, 0, 0, 0, 0, 0, 0,
644 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
645 0, 0, 0, 0, 0, 0, 0, 0, 0,
646 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
647 -1, 0, 0, -1, 0, 0, -1, 0, 0,
648 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
649 -1, 0, 0, -1, 0, 0, -1, 0, 0,
650 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
651 -1, -1, 0, -1, 0, 0, -1, 0, 0,
652 -1, -1, -1, -1, -1, 0, -1, 0, -1, -1,
653 -1, -1, 0, -1, 0, 0, -1, 0, 0,
654 -1, -1, -1, -1, -1, 0, -1, 0, -1, -1,
655 -1, -1, 0, -1, -1, -1, -1, -1, 0,
656 0, 0, -1, 0, -1, 0, -1, -1, -1, 0,
657 -1, -1, 0, -1, -1, -1, -1, -1, 0,
658 0, 0, -1, 0, -1, 0, -1, -1, -1, 0,
659 -1, 0, 0, 0, 0, 0, -1, 0, 0,
660 0, -1, -1, 0, 0, 0, -1, 0, 0, 0,
661 -1, 0, 0, 0, 0, 0, -1, 0, 0,
662 0, -1, -1, 0, 0, 0, -1, 0, 0, 0,
663 -1, 0, 0, -1, 0, 0, -1, 0, 0,
664 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
665 -1, 0, 0, -1, 0, 0, -1, 0, 0,
666 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
667 -1, 0, 0, 0, -1, 0, 0, 0, 0,
668 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
669 -1, 0, 0, 0, -1, 0, 0, 0, 0,
670 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
671 0, -1, 0, -1, -1, 0, -1, 0, 0,
672 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
673 0, -1, 0, -1, -1, 0, 0, 0, 0,
674 0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
675 -1, 0, 0, -1, 0, 0, -1, 0, 0,
676 0, 0, -1, 0, 0, 0, -1, 0, -1, 0,
677 -1, 0, 0, -1, 0, 0, -1, 0, 0,
678 0, 0, -1, 0, 0, 0, -1, 0, -1, 0,
679 0, 0, 0, 0, 0, 0, 0, 0, 0,
680 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
681 0, 0, 0, 0, 0, 0, 0, 0, 0,
682 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
683 -1, 0, 0, 0, 0, 0, 0, 0, 0,
684 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
685 -1, 0, 0, 0, 0, 0, 0, 0, 0,
686 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
687 0, -1, 0, 0, -1, 0, 0, 0, -1,
688 -1, -1, 0, -1, -1, -1, 0, 0, 0, 0,
689 0, -1, 0, 0, -1, 0, 0, 0, -1,
690 -1, -1, 0, -1, -1, -1, 0, 0, 0, 0,
691 0, 0, 0, 0, 0, 0, 0, 0, 0,
692 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
693 0, 0, 0, 0, 0, 0, 0, 0, 0,
694 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
695 0, 0, 0, 0, 0, 0, 0, 0, 0,
696 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
697 0, 0, 0, 0, 0, 0, 0, 0, 0,
698 0, 0, -1, 0, 0, 0, -1, 0, 0, 0,
699 -1, 0, 0, -1, 0, 0, -1, 0, 0,
700 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
701 -1, 0, 0, -1, 0, 0, -1, 0, 0,
702 0, 0, 0, 0, 0, 0, -1, 0, 0, 0,
703 0, -1, -1, -1, 0, 0, 0, 0, 0,
704 -1, -1, 0, -1, -1, -1, 0, 0, 0, -1,
705 0, -1, -1, -1, 0, 0, 0, 0, 0,
706 -1, -1, 0, -1, -1, -1, 0, 0, 0, -1
707 #endif
708 };
709
710 /*
711 --- T.61 characters [0xA0 .. 0xBF] -----------------
712 */
713 static Couple trans_t61a_iso8859[32] = {
714 #if (ISO_8859 == 1) || (ISO_8859 == 9)
715 {'N','S'}, {0xa1,0}, {0xa2,0}, {0xa3,0},
716 {'D','O'}, {0xa5,0}, {'C','u'}, {0xa7,0},
717 {0xa4,0}, {'\'','6'},{'"','6'}, {0xab,0},
718 {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
719 {0xb0,0}, {0xb1,0}, {0xb2,0}, {0xb3,0},
720 {0xd7,0}, {0xb5,0}, {0xb6,0}, {0xb7,0},
721 {0xf7,0}, {'\'','9'},{'"','9'}, {0xbb,0},
722 {0xbc,0}, {0xbd,0}, {0xbe,0}, {0xbf,0}
723 #elif (ISO_8859 == 2) || (ISO_8859 == 4)
724 {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'},
725 {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0},
726 {0xa4,0}, {'\'','6'},{'"','6'}, {'<','<'},
727 {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
728 {0xb0,0}, {'+','-'}, {'2','S'}, {'3','S'},
729 {0xd7,0}, {'M','y'}, {'P','I'}, {'.','M'},
730 {0xf7,0}, {'\'','9'},{'"','9'}, {'>','>'},
731 {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'},
732 #elif (ISO_8859 == 3)
733 {'N','S'}, {'!','I'}, {'C','t'}, {0xa3,0},
734 {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0},
735 {0xa4,0}, {'\'','6'},{'"','6'}, {'<','<'},
736 {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
737 {0xb0,0}, {'+','-'}, {0xb2,0}, {0xb3,0},
738 {0xd7,0}, {0xb5,0}, {'P','I'}, {0xb7,0},
739 {0xf7,0}, {'\'','9'},{'"','9'}, {'>','>'},
740 {'1','4'}, {0xbd,0}, {'3','4'}, {'?','I'}
741 #elif (ISO_8859 == 10)
742 {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'},
743 {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0},
744 {'C','u'}, {'\'','6'},{'"','6'}, {'<','<'},
745 {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
746 {0xb0,0}, {'+','-'}, {'2','S'}, {'3','S'},
747 {'*','X'}, {'M','y'}, {'P','I'}, {0xb7,0},
748 {'-',':'}, {'\'','9'},{'"','9'}, {'>','>'},
749 {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'}
750 #else
751 {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'},
752 {'D','O'}, {'Y','e'}, {'C','u'}, {'S','E'},
753 {'X','O'}, {'\'','6'},{'"','6'}, {'<','<'},
754 {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
755 {'D','G'}, {'+','-'}, {'2','S'}, {'3','S'},
756 {'*','X'}, {'M','y'}, {'P','I'}, {'.','M'},
757 {'-',':'}, {'\'','9'},{'"','9'}, {'>','>'},
758 {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'}
759 #endif
760 };
761
762 /*
763 --- T.61 characters [0xE0 .. 0xFF] -----------------
764 */
765 static Couple trans_t61b_iso8859[48] = {
766 #if (ISO_8859 == 1)
767 {'-','M'}, {0xb9,0}, {0xae,0}, {0xa9,0},
768 {'T','M'}, {'M','8'}, {0xac,0}, {0xa6,0},
769 {0,0}, {0,0}, {0,0}, {0,0},
770 {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
771 {'O','m'}, {0xc6,0}, {0xd0,0}, {0xaa,0},
772 {'H','/'}, {0,0}, {'I','J'}, {'L','.'},
773 {'L','/'}, {0xd8,0}, {'O','E'}, {0xba,0},
774 {0xde,0}, {'T','/'}, {'N','G'}, {'\'','n'},
775 {'k','k'}, {0xe6,0}, {'d','/'}, {0xf0,0},
776 {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
777 {'l','/'}, {0xf8,0}, {'o','e'}, {0xdf,0},
778 {0xfe,0}, {'t','/'}, {'n','g'}, {'-','-'}
779 #elif (ISO_8859 == 2)
780 {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
781 {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
782 {0,0}, {0,0}, {0,0}, {0,0},
783 {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
784 {'O','m'}, {'A','E'}, {0xd0,0}, {'-','a'},
785 {'H','/'}, {0,0}, {'I','J'}, {'L','.'},
786 {0xa3,0}, {'O','/'}, {'O','E'}, {'-','o'},
787 {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
788 {'k','k'}, {'a','e'}, {0xf0,0}, {'d','-'},
789 {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
790 {0xb3,0}, {'o','/'}, {'o','e'}, {0xdf,0},
791 {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'}
792 #elif (ISO_8859 == 3)
793 {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
794 {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
795 {0,0}, {0,0}, {0,0}, {0,0},
796 {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
797 {'O','m'}, {'A','E'}, {'D','/'}, {'-','a'},
798 {0xa1,0}, {0,0}, {'I','J'}, {'L','.'},
799 {'L','/'}, {'O','/'}, {'O','E'}, {'-','o'},
800 {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
801 {'k','k'}, {'a','e'}, {'d','/'}, {'d','-'},
802 {0xb1,0}, {0xb9,0}, {'i','j'}, {'l','.'},
803 {'l','/'}, {'o','/'}, {'o','e'}, {0xdf,0},
804 {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'}
805 #elif (ISO_8859 == 4)
806 {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
807 {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
808 {0,0}, {0,0}, {0,0}, {0,0},
809 {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
810 {'O','m'}, {0xc6,0}, {0xd0,0}, {'-','a'},
811 {'H','/'}, {0,0}, {'I','J'}, {'L','.'},
812 {'L','/'}, {0xd8,0}, {'O','E'}, {'-','o'},
813 {'T','H'}, {0xac,0}, {0xbd,0}, {'\'','n'},
814 {0xa2,0}, {0xe6,0}, {0xf0,0}, {'d','-'},
815 {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
816 {'l','/'}, {0xf8,0}, {'o','e'}, {0xdf,0},
817 {'t','h'}, {0xbc,0}, {0xbf,0}, {'-','-'}
818 #elif (ISO_8859 == 9)
819 {'-','M'}, {0xb9,0}, {0xae,0}, {0xa9,0},
820 {'T','M'}, {'M','8'}, {0xac,0}, {0xa6,0},
821 {0,0}, {0,0}, {0,0}, {0,0},
822 {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
823 {'O','m'}, {0xc6,0}, {'D','/'}, {0xaa,0},
824 {'H','/'}, {0,0}, {'I','J'}, {'L','.'},
825 {'L','/'}, {0xd8,0}, {'O','E'}, {0xba,0},
826 {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
827 {'k','k'}, {0xe6,0}, {'d','/'}, {'d','-'},
828 {'h','/'}, {0xfd,0}, {'i','j'}, {'l','.'},
829 {'l','/'}, {0xf8,0}, {'o','e'}, {0xdf,0},
830 {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'}
831 #elif (ISO_8859 == 10)
832 {0xbd,0}, {'1','S'}, {'R','g'}, {'C','o'},
833 {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
834 {0,0}, {0,0}, {0,0}, {0,0},
835 {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
836 {'O','m'}, {0xc6,0}, {0xa9,0}, {'-','a'},
837 {'H','/'}, {0,0}, {'I','J'}, {'L','.'},
838 {'L','/'}, {0xd8,0}, {'O','E'}, {'-','o'},
839 {0xde,0}, {0xab,0}, {0xaf,0}, {'\'','n'},
840 {0xff,0}, {0xe6,0}, {0xb9,0}, {0xf0,0},
841 {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
842 {'l','/'}, {0xf8,0}, {'o','e'}, {0xdf,0},
843 {0xfe,0}, {0xbb,0}, {0xbf,0}, {'-','-'}
844 #else
845 {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
846 {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
847 {0,0}, {0,0}, {0,0}, {0,0},
848 {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
849 {'O','m'}, {'A','E'}, {'D','/'}, {'-','a'},
850 {'H','/'}, {0,0}, {'I','J'}, {'L','.'},
851 {'L','/'}, {'O','/'}, {'O','E'}, {'-','o'},
852 {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
853 {'k','k'}, {'a','e'}, {'d','/'}, {'d','-'},
854 {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
855 {'l','/'}, {'o','/'}, {'o','e'}, {'s','s'},
856 {'t','h'}, {'t','-'}, {'n','g'}, {'-','-'}
857 #endif
858 };
859
860 /*
861 --- ISO 8859-n characters <0xA0 .. 0xFF> -------------------
862 */
863 #if (ISO_8859 == 1)
864 static Couple trans_iso8859_t61[96] = {
865 {0xa0,0}, {0xa1,0}, {0xa2,0}, {0xa3,0},
866 {0xa8,0}, {0xa5,0}, {0xd7,0}, {0xa7,0},
867 {0xc8,ALONE}, {0xd3,0}, {0xe3,0}, {0xab,0},
868 {0xd6,0}, {0xff,0}, {0xd2,0}, {0xc5,ALONE},
869 {0xb0,0}, {0xb1,0}, {0xb2,0}, {0xb3,0},
870 {0xc2,ALONE}, {0xb5,0}, {0xb6,0}, {0xb7,0},
871 {0xcb,ALONE}, {0xd1,0}, {0xeb,0}, {0xbb,0},
872 {0xbc,0}, {0xbd,0}, {0xbe,0}, {0xbf,0},
873 {0xc1,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0xc4,'A'},
874 {0xc8,'A'}, {0xca,'A'}, {0xe1,0}, {0xcb,'C'},
875 {0xc1,'E'}, {0xc2,'E'}, {0xc3,'E'}, {0xc8,'E'},
876 {0xc1,'I'}, {0xc2,'I'}, {0xc3,'I'}, {0xc8,'I'},
877 {0xe2,0}, {0xc4,'N'}, {0xc1,'O'}, {0xc2,'O'},
878 {0xc3,'O'}, {0xc4,'O'}, {0xc8,'O'}, {0xb4,0},
879 {0xe9,0}, {0xc1,'U'}, {0xc2,'U'}, {0xc3,'U'},
880 {0xc8,'U'}, {0xc2,'Y'}, {0xec,0}, {0xfb,0},
881 {0xc1,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0xc4,'a'},
882 {0xc8,'a'}, {0xca,'a'}, {0xf1,0}, {0xcb,'c'},
883 {0xc1,'e'}, {0xc2,'e'}, {0xc3,'e'}, {0xc8,'e'},
884 {0xc1,'i'}, {0xc2,'i'}, {0xc3,'i'}, {0xc8,'i'},
885 {0xf3,0}, {0xc4,'n'}, {0xc1,'o'}, {0xc2,'o'},
886 {0xc3,'o'}, {0xc4,'o'}, {0xc8,'o'}, {0xb8,0},
887 {0xf9,0}, {0xc1,'u'}, {0xc2,'u'}, {0xc3,'u'},
888 {0xc8,'u'}, {0xc2,'y'}, {0xfc,0}, {0xc8,'y'}
889 };
890 #elif (ISO_8859 == 2)
891 static Couple trans_iso8859_t61[96] = {
892 {0xa0,0}, {0xce,'A'}, {0xc6,ALONE}, {0xe8,0},
893 {0xa8,0}, {0xcf,'L'}, {0xc2,'S'}, {0xa7,0},
894 {0xc8,ALONE}, {0xcf,'S'}, {0xcb,'S'}, {0xcf,'T'},
895 {0xc2,'Z'}, {0xff,0}, {0xcf,'Z'}, {0xc7,'Z'},
896 {0xb0,0}, {0xce,'a'}, {0xce,ALONE}, {0xf8,0},
897 {0xc2,ALONE}, {0xcf,'l'}, {0xc2,'s'}, {0xcf,ALONE},
898 {0xcb,ALONE}, {0xcf,'s'}, {0xcb,'s'}, {0xcf,'t'},
899 {0xc2,'z'}, {0xcd,ALONE}, {0xcf,'z'}, {0xc7,'z'},
900 {0xc2,'R'}, {0xc2,'A'}, {0xc3,'A'}, {0xc6,'A'},
901 {0xc8,'A'}, {0xc2,'L'}, {0xc2,'C'}, {0xcb,'C'},
902 {0xcf,'C'}, {0xc2,'E'}, {0xce,'E'}, {0xc8,'E'},
903 {0xcf,'E'}, {0xc2,'I'}, {0xc3,'I'}, {0xcf,'D'},
904 {0xe2,0}, {0xc2,'N'}, {0xcf,'N'}, {0xc2,'O'},
905 {0xc3,'O'}, {0xcd,'O'}, {0xc8,'O'}, {0xb4,0},
906 {0xcf,'R'}, {0xca,'U'}, {0xc2,'U'}, {0xcd,'U'},
907 {0xc8,'U'}, {0xc2,'Y'}, {0xcb,'T'}, {0xfb,0},
908 {0xc2,'r'}, {0xc2,'a'}, {0xc3,'a'}, {0xc6,'a'},
909 {0xc8,'a'}, {0xc2,'l'}, {0xc2,'c'}, {0xcb,'c'},
910 {0xcf,'c'}, {0xc2,'e'}, {0xce,'e'}, {0xc8,'e'},
911 {0xcf,'e'}, {0xc2,'i'}, {0xc3,'i'}, {0xcf,'d'},
912 {0xf2,0}, {0xc2,'n'}, {0xcf,'n'}, {0xc2,'o'},
913 {0xc3,'o'}, {0xcd,'o'}, {0xc8,'o'}, {0xb8,0},
914 {0xcf,'r'}, {0xca,'u'}, {0xc2,'u'}, {0xcd,'u'},
915 {0xc8,'u'}, {0xc2,'y'}, {0xcb,'t'}, {0xc7,ALONE}
916 };
917 #elif (ISO_8859 == 3)
918 static Couple trans_iso8859_t61[96] = {
919 {0xa0,0}, {0xe4,0}, {0xc6,ALONE}, {0xa3,0},
920 {0xa8,0}, {0,0}, {0xc3,'H'}, {0xa7,0},
921 {0xc8,ALONE}, {0xc7,'I'}, {0xcb,'S'}, {0xc6,'G'},
922 {0xc3,'J'}, {0xff,0}, {0,0}, {0xc7,'Z'},
923 {0xb0,0}, {0xf4,0}, {0xb2,0}, {0xb3,0},
924 {0xc2,ALONE}, {0xb5,0}, {0xc3,'h'}, {0xb7,0},
925 {0xcb,ALONE}, {0xf5,0}, {0xcb,'s'}, {0xc6,'g'},
926 {0xc3,'j'}, {0xbd,0}, {0,0}, {0xc7,'z'},
927 {0xc1,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0,0},
928 {0xc8,'A'}, {0xc7,'C'}, {0xc3,'C'}, {0xcb,'C'},
929 {0xc1,'E'}, {0xc2,'E'}, {0xc3,'E'}, {0xc8,'E'},
930 {0xc1,'I'}, {0xc2,'I'}, {0xc3,'I'}, {0xc8,'I'},
931 {0,0}, {0xc4,'N'}, {0xc1,'O'}, {0xc2,'O'},
932 {0xc3,'O'}, {0xc7,'G'}, {0xc8,'O'}, {0xb4,0},
933 {0xc3,'G'}, {0xc1,'U'}, {0xc2,'U'}, {0xc3,'U'},
934 {0xc8,'U'}, {0xc6,'U'}, {0xc3,'S'}, {0xfb,0},
935 {0xc1,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0,0},
936 {0xc8,'a'}, {0xc7,'c'}, {0xc3,'c'}, {0xcb,'c'},
937 {0xc1,'e'}, {0xc2,'e'}, {0xc3,'e'}, {0xc8,'e'},
938 {0xc1,'i'}, {0xc2,'i'}, {0xc3,'i'}, {0xc8,'i'},
939 {0,0}, {0xc4,'n'}, {0xc1,'o'}, {0xc2,'o'},
940 {0xc3,'o'}, {0xc7,'g'}, {0xc8,'o'}, {0xb8,0},
941 {0xc3,'g'}, {0xc1,'u'}, {0xc2,'u'}, {0xc3,'u'},
942 {0xc8,'u'}, {0xc6,'u'}, {0xc3,'s'}, {0xc7,ALONE}
943 };
944 #elif (ISO_8859 == 4)
945 static Couple trans_iso8859_t61[96] = {
946 {0xa0,0}, {0xce,'A'}, {0xf0,0}, {0xcb,'R'},
947 {0xa8,0}, {0xc4,'I'}, {0xcb,'L'}, {0xa7,0},
948 {0xc8,ALONE}, {0xcf,'S'}, {0xc5,'E'}, {0xcb,'G'},
949 {0xed,0}, {0xff,0}, {0xcf,'Z'}, {0xc5,ALONE},
950 {0xb0,0}, {0xce,'a'}, {0xce,ALONE}, {0xcb,'r'},
951 {0xc2,ALONE}, {0xc4,'i'}, {0xcb,'l'}, {0xcf,ALONE},
952 {0xcb,ALONE}, {0xcf,'s'}, {0xc5,'e'}, {0xcb,'g'},
953 {0xfd,0}, {0xee,0}, {0xcf,'z'}, {0xfe,0},
954 {0xc5,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0xc4,'A'},
955 {0xc8,'A'}, {0xca,'A'}, {0xe1,0}, {0xce,'I'},
956 {0xcf,'C'}, {0xc2,'E'}, {0xce,'E'}, {0xc8,'E'},
957 {0xc7,'E'}, {0xc2,'I'}, {0xc3,'I'}, {0xc5,'I'},
958 {0xe2,0}, {0xcb,'N'}, {0xc5,'O'}, {0xcb,'K'},
959 {0xc3,'O'}, {0xc4,'O'}, {0xc8,'O'}, {0xb4,0},
960 {0xe9,0}, {0xce,'U'}, {0xc2,'U'}, {0xc3,'U'},
961 {0xc8,'U'}, {0xc4,'U'}, {0xc5,'U'}, {0xfb,0},
962 {0xc5,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0xc4,'a'},
963 {0xc8,'a'}, {0xca,'a'}, {0xf1,0}, {0xce,'i'},
964 {0xcf,'c'}, {0xc2,'e'}, {0xce,'e'}, {0xc8,'e'},
965 {0xc7,'e'}, {0xc2,'i'}, {0xc3,'i'}, {0xc5,'i'},
966 {0xf2,0}, {0xcb,'n'}, {0xc5,'o'}, {0xcb,'k'},
967 {0xc3,'o'}, {0xc4,'o'}, {0xc8,'o'}, {0xb8,0},
968 {0xf9,0}, {0xce,'u'}, {0xc2,'u'}, {0xc3,'u'},
969 {0xc8,'u'}, {0xc4,'u'}, {0xc5,'u'}, {0xc7,ALONE}
970 };
971 #elif (ISO_8859 == 9)
972 static Couple trans_iso8859_t61[96] = {
973 {0xa0,0}, {0xa1,0}, {0xa2,0}, {0xa3,0},
974 {0xa8,0}, {0xa5,0}, {0xd7,0}, {0xa7,0},
975 {0xc8,ALONE}, {0xd3,0}, {0xe3,0}, {0xab,0},
976 {0xd6,0}, {0xff,0}, {0xd2,0}, {0xc5,ALONE},
977 {0xb0,0}, {0xb1,0}, {0xb2,0}, {0xb3,0},
978 {0xc2,ALONE}, {0xb5,0}, {0xb6,0}, {0xb7,0},
979 {0xcb,ALONE}, {0xd1,0}, {0xeb,0}, {0xbb,0},
980 {0xbc,0}, {0xbd,0}, {0xbe,0}, {0xbf,0},
981 {0xc1,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0xc4,'A'},
982 {0xc8,'A'}, {0xca,'A'}, {0xe1,0}, {0xcb,'C'},
983 {0xc1,'E'}, {0xc2,'E'}, {0xc3,'E'}, {0xc8,'E'},
984 {0xc1,'I'}, {0xc2,'I'}, {0xc3,'I'}, {0xc8,'I'},
985 {0xc6,'G'}, {0xc4,'N'}, {0xc1,'O'}, {0xc2,'O'},
986 {0xc3,'O'}, {0xc4,'O'}, {0xc8,'O'}, {0xb4,0},
987 {0xe9,0}, {0xc1,'U'}, {0xc2,'U'}, {0xc3,'U'},
988 {0xc8,'U'}, {0xc7,'I'}, {0xcb,'S'}, {0xfb,0},
989 {0xc1,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0xc4,'a'},
990 {0xc8,'a'}, {0xca,'a'}, {0xf1,0}, {0xcb,'c'},
991 {0xc1,'e'}, {0xc2,'e'}, {0xce,'e'}, {0xc8,'e'},
992 {0xc7,'e'}, {0xc2,'i'}, {0xc3,'i'}, {0xc5,'i'},
993 {0xc6,'g'}, {0xc4,'n'}, {0xc1,'o'}, {0xc2,'o'},
994 {0xc3,'o'}, {0xc4,'o'}, {0xc8,'o'}, {0xb8,0},
995 {0xf9,0}, {0xc1,'u'}, {0xc2,'u'}, {0xc3,'u'},
996 {0xc8,'u'}, {0xf5,0}, {0xcb,'s'}, {0xc8,'y'}
997 };
998 #elif (ISO_8859 == 10)
999 static Couple trans_iso8859_t61[96] = {
1000 {0xa0,0}, {0xce,'A'}, {0xc5,'E'}, {0xcb,'G'},
1001 {0xc5,'I'}, {0xc4,'I'}, {0xcb,'K'}, {0xa7,0},
1002 {0xcb,'L'}, {0xe2,0}, {0xcf,'S'}, {0xed,0},
1003 {0xcf,'Z'}, {0xff,0}, {0xc5,'U'}, {0xee,0},
1004 {0xb0,0}, {0xce,'a'}, {0xc5,'e'}, {0xcb,'g'},
1005 {0xc5,'i'}, {0xc4,'i'}, {0xcb,'k'}, {0xb7,0},
1006 {0xcb,'l'}, {0xf2,0}, {0xcf,'s'}, {0xfd,0},
1007 {0xcf,'z'}, {0xd0,0}, {0xc5,'u'}, {0xfe,0},
1008 {0xc5,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0xc4,'A'},
1009 {0xc8,'A'}, {0xca,'A'}, {0xe1,0}, {0xce,'I'},
1010 {0xcf,'C'}, {0xc2,'E'}, {0xce,'E'}, {0xc8,'E'},
1011 {0xc7,'E'}, {0xc2,'I'}, {0xc3,'I'}, {0xc8,'I'},
1012 {0,0}, {0xcb,'N'}, {0xc5,'O'}, {0xc2,'O'},
1013 {0xc3,'O'}, {0xc4,'O'}, {0xc8,'O'}, {0xc4,'U'},
1014 {0xe9,0}, {0xce,'U'}, {0xc2,'U'}, {0xc3,'U'},
1015 {0xc8,'U'}, {0xc2,'Y'}, {0xec,0}, {0xfb,0},
1016 {0xc5,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0xc4,'a'},
1017 {0xc8,'a'}, {0xca,'a'}, {0xf1,0}, {0xce,'i'},
1018 {0xcf,'c'}, {0xc2,'e'}, {0xce,'e'}, {0xc8,'e'},
1019 {0xc7,'e'}, {0xc2,'i'}, {0xc3,'i'}, {0xc8,'i'},
1020 {0xf3,0}, {0xcb,'n'}, {0xc5,'o'}, {0xc2,'o'},
1021 {0xc3,'o'}, {0xc4,'o'}, {0xc8,'o'}, {0xc4,'u'},
1022 {0xf9,0}, {0xce,'u'}, {0xc2,'u'}, {0xc3,'u'},
1023 {0xc8,'u'}, {0xc2,'y'}, {0xfc,0}, {0xf0,0}
1024 };
1025 #endif
1026
1027
1028 static Byte *
c_to_hh(Byte * o,Byte c)1029 c_to_hh( Byte *o, Byte c )
1030 {
1031 Byte n;
1032
1033 *o++ = '{'; *o++ = 'x';
1034 n = c >> 4;
1035 *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
1036 n = c & 0x0F;
1037 *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
1038 *o++ = '}';
1039 return o;
1040 }
1041
1042
1043 static Byte *
c_to_cc(Byte * o,Couple * cc,Byte c)1044 c_to_cc( Byte *o, Couple *cc, Byte c )
1045 {
1046 if ( (*cc).a != 0 ) {
1047 if ( (*cc).b == 0 )
1048 *o++ = (*cc).a;
1049 else {
1050 *o++ = '{';
1051 *o++ = (*cc).a;
1052 *o++ = (*cc).b;
1053 *o++ = '}';
1054 }
1055 return o;
1056 }
1057 else
1058 return c_to_hh( o, c );
1059 }
1060
1061 /* --- routine to convert from T.61 to ISO 8859-n --- */
1062
1063 int
ldap_t61_to_8859(char ** bufp,unsigned long * buflenp,int free_input)1064 ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input )
1065 {
1066 Byte *s, *oo, *o;
1067 unsigned int n;
1068 int c;
1069 unsigned long len;
1070 Couple *cc;
1071
1072 LDAPDebug( LDAP_DEBUG_TRACE, "ldap_t61_to_8859 input length: %ld\n",
1073 *buflenp, 0, 0 );
1074
1075 len = *buflenp;
1076 s = (Byte *) *bufp;
1077
1078 if ( (o = oo = (Byte *)NSLDAPI_MALLOC( 2 * len + 64 )) == NULL ) {
1079 return( 1 );
1080 }
1081
1082 while ( (char *)s - *(char **)bufp < len ) {
1083 switch ( *s >> 4 ) {
1084
1085 case 0xA: case 0xB:
1086 o = c_to_cc( o, &trans_t61a_iso8859[ *s - 0xA0 ], *s );
1087 s++;
1088 break;
1089
1090 case 0xD: case 0xE: case 0xF:
1091 o = c_to_cc( o, &trans_t61b_iso8859[ *s - 0xD0 ], *s );
1092 s++;
1093 break;
1094
1095 case 0xC:
1096 if ( (*s == 0xC0) || (*s == 0xC9) || (*s == 0xCC) ) {
1097 o = c_to_hh( o, *s++ );
1098 break;
1099 }
1100
1101 n = (*s++) - 0xC0;
1102 switch ( *s ) {
1103
1104 case 'A': c = letter_w_diacritic[n][0]; break;
1105 case 'C': c = letter_w_diacritic[n][1]; break;
1106 case 'D': c = letter_w_diacritic[n][2]; break;
1107 case 'E': c = letter_w_diacritic[n][3]; break;
1108 case 'G': c = letter_w_diacritic[n][4]; break;
1109 case 'H': c = letter_w_diacritic[n][5]; break;
1110 case 'I': c = letter_w_diacritic[n][6]; break;
1111 case 'J': c = letter_w_diacritic[n][7]; break;
1112 case 'K': c = letter_w_diacritic[n][8]; break;
1113 case 'L': c = letter_w_diacritic[n][9]; break;
1114 case 'N': c = letter_w_diacritic[n][10]; break;
1115 case 'O': c = letter_w_diacritic[n][11]; break;
1116 case 'R': c = letter_w_diacritic[n][12]; break;
1117 case 'S': c = letter_w_diacritic[n][13]; break;
1118 case 'T': c = letter_w_diacritic[n][14]; break;
1119 case 'U': c = letter_w_diacritic[n][15]; break;
1120 case 'W': c = letter_w_diacritic[n][16]; break;
1121 case 'Y': c = letter_w_diacritic[n][17]; break;
1122 case 'Z': c = letter_w_diacritic[n][18]; break;
1123
1124 case 'a': c = letter_w_diacritic[n][19]; break;
1125 case 'c': c = letter_w_diacritic[n][20]; break;
1126 case 'd': c = letter_w_diacritic[n][21]; break;
1127 case 'e': c = letter_w_diacritic[n][22]; break;
1128 case 'g': c = letter_w_diacritic[n][23]; break;
1129 case 'h': c = letter_w_diacritic[n][24]; break;
1130 case 'i': c = letter_w_diacritic[n][25]; break;
1131 case 'j': c = letter_w_diacritic[n][26]; break;
1132 case 'k': c = letter_w_diacritic[n][27]; break;
1133 case 'l': c = letter_w_diacritic[n][28]; break;
1134 case 'n': c = letter_w_diacritic[n][29]; break;
1135 case 'o': c = letter_w_diacritic[n][30]; break;
1136 case 'r': c = letter_w_diacritic[n][31]; break;
1137 case 's': c = letter_w_diacritic[n][32]; break;
1138 case 't': c = letter_w_diacritic[n][33]; break;
1139 case 'u': c = letter_w_diacritic[n][34]; break;
1140 case 'w': c = letter_w_diacritic[n][35]; break;
1141 case 'y': c = letter_w_diacritic[n][36]; break;
1142 case 'z': c = letter_w_diacritic[n][37]; break;
1143
1144 case ALONE: c = (( !diacritic[n].b ) ? diacritic[n].a : -1);
1145 break;
1146
1147 default: c = 0;
1148 }
1149
1150 if ( c > 0 ) {
1151 *o++ = c; s++;
1152 } else {
1153 *o++ = '{';
1154 if ( c == -1 ) {
1155 *o++ = ( ( *s == ALONE ) ? ' ' : *s );
1156 s++;
1157 } else {
1158 *o++ = '"';
1159 }
1160 *o++ = diacritic[n].a;
1161 *o++ = '}';
1162 }
1163 break;
1164
1165 #if (ISO_8859 == 0)
1166 case 0x8: case 0x9:
1167 *o++ = 0x1B; /* <ESC> */
1168 *o++ = *s++ - 0x40;
1169 break;
1170 #endif
1171
1172 default:
1173 *o++ = *s++;
1174 }
1175 }
1176
1177 len = o - oo;
1178 o = oo;
1179
1180 if ( (oo = (Byte *)NSLDAPI_REALLOC( o, len )) == NULL ) {
1181 NSLDAPI_FREE( o );
1182 return( 1 );
1183 }
1184
1185 if ( free_input ) {
1186 NSLDAPI_FREE( *bufp );
1187 }
1188 *bufp = (char *) oo;
1189 *buflenp = len;
1190 return( 0 );
1191 }
1192
1193
1194 static int
hh_to_c(Byte * h)1195 hh_to_c( Byte *h )
1196 {
1197 Byte c;
1198
1199 if ( (*h >= '0') && (*h <= '9') ) c = *h++ - '0';
1200 else if ( (*h >= 'A') && (*h <= 'F') ) c = *h++ - 'A' + 10;
1201 else if ( (*h >= 'a') && (*h <= 'f') ) c = *h++ - 'a' + 10;
1202 else return -1;
1203
1204 c <<= 4;
1205
1206 if ( (*h >= '0') && (*h <= '9') ) c |= *h - '0';
1207 else if ( (*h >= 'A') && (*h <= 'F') ) c |= *h - 'A' + 10;
1208 else if ( (*h >= 'a') && (*h <= 'f') ) c |= *h - 'a' + 10;
1209 else return -1;
1210
1211 return c;
1212 }
1213
1214
1215 static Byte *
cc_to_t61(Byte * o,Byte * s)1216 cc_to_t61( Byte *o, Byte *s )
1217 {
1218 int n, c = 0;
1219
1220 switch ( *(s + 1) ) {
1221
1222 case '`': c = -1; break; /* <grave-accent> */
1223
1224 case '!':
1225 switch ( *s ) {
1226 case '!': c = 0x7C; break; /* <vertical-line> */
1227 case '(': c = 0x7B; break; /* <left-curly-bracket> */
1228 case '-': c = 0xAD; break; /* <upwards-arrow> */
1229 default: c = -1; /* <grave-accent> */
1230 }
1231 break;
1232
1233 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1234 (ISO_8859 == 4) || (ISO_8859 == 9)
1235 case 0xB4:
1236 #endif
1237 case '\'': c = -2; break; /* <acute-accent> */
1238
1239 case '^': c = -3; break; /* <circumflex-acent> */
1240
1241 case '>':
1242 switch ( *s ) {
1243 case ')': c = 0x5D; break; /* <right-square-bracket> */
1244 case '>': c = 0xBB; break; /* <right-angle-quotation> */
1245 case '-': c = 0xAE; break; /* <rightwards-arrow> */
1246 default: c = -3; /* <circumflex-acent> */
1247 }
1248 break;
1249
1250 case '~':
1251 case '?': c = -4; break; /* <tilde> */
1252
1253 #if (ISO_8859 == 1) || (ISO_8859 == 4) || (ISO_8859 == 9)
1254 case 0xAF: c = -5; break; /* <macron> */
1255 #endif
1256
1257 case '-':
1258 switch ( *s ) {
1259 case '-': c = 0xFF; break; /* <soft-hyphen> */
1260 case '<': c = 0xAC; break; /* <leftwards arrow> */
1261 case '+': c = 0xB1; break; /* <plus-minus> */
1262 case 'd': c = 0xF3; break; /* <eth> */
1263 default: c = -5; /* <macron> */
1264 }
1265 break;
1266
1267 #if (ISO_8859 == 2) || (ISO_8859 == 3)
1268 case 0xA2: c = -6; break; /* <breve> */
1269 #endif
1270
1271 case '(':
1272 if ( *s == '<' ) c = 0x5B; /* <left-square-bracket> */
1273 else c = -6; /* <breve> */
1274 break;
1275
1276 #if (ISO_8859 == 2) || (ISO_8859 == 3) || (ISO_8859 == 4)
1277 case 0xFF: c = -7; break; /* <dot-accent> */
1278 #endif
1279
1280 case '.':
1281 switch ( *s ) {
1282 case 'i': c = 0xF5; break; /* <dotless-i> */
1283 case 'L': c = 0xE7; break; /* <L-middle-dot> */
1284 case 'l': c = 0xF7; break; /* <l-middle-dot> */
1285 default: c = -7; /* <dot-accent> */
1286 }
1287 break;
1288
1289 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1290 (ISO_8859 == 4) || (ISO_8859 == 9)
1291 case 0xA8: c = -8; break; /* <diaeresis> */
1292 #endif
1293
1294 case ':':
1295 if ( *s == '-') c = 0xB8; /* <division-sign> */
1296 else c = -8; /* <diaeresis> */
1297 break;
1298
1299 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1300 (ISO_8859 == 4) || (ISO_8859 == 9) || (ISO_8859 == 10)
1301 case 0xB0:
1302 #endif
1303 case '0': c = -10; break; /* <ring-above> */
1304
1305 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1306 (ISO_8859 == 4) || (ISO_8859 == 9)
1307 case 0xB8:
1308 #endif
1309 case ',': c = -11; break; /* <cedilla> */
1310
1311 #if (ISO_8859 == 2)
1312 case 0xBD:
1313 #endif
1314 case '"': c = -13; break; /* <double-acute-accent> */
1315
1316 #if (ISO_8859 == 2) || (ISO_8859 == 4)
1317 case 0xB2:
1318 #endif
1319 case ';': c = -14; break; /* <ogonek> */
1320
1321 #if (ISO_8859 == 2) || (ISO_8859 == 4)
1322 case 0xB7: c = -15; break; /* <caron> */
1323 #endif
1324
1325 case ')':
1326 if ( *s == '!' ) c = 0x7D; /* <left-curly-bracket> */
1327 break;
1328
1329 case '<':
1330 if ( *s == '<' ) c = 0xAB; /* <left-angle-quotation> */
1331 else c = -15; /* <caron> */
1332 break;
1333
1334 case '/':
1335 switch ( *s ) {
1336 case '/': c = 0x5C; break; /* <reverse-solidus> */
1337 case 'D': c = 0xE2; break; /* <D-stroke> */
1338 case 'd': c = 0xF2; break; /* <d-stroke> */
1339 case 'H': c = 0xE4; break; /* <H-stroke> */
1340 case 'h': c = 0xF4; break; /* <h-stroke> */
1341 case 'L': c = 0xE8; break; /* <L-stroke> */
1342 case 'l': c = 0xF8; break; /* <l-stroke> */
1343 case 'O': c = 0xE9; break; /* <O-stroke> */
1344 case 'o': c = 0xF9; break; /* <o-stroke> */
1345 case 'T': c = 0xED; break; /* <T-stroke> */
1346 case 't': c = 0xFD; break; /* <t-stroke> */
1347 }
1348 break;
1349
1350 case '2':
1351 if ( *s == '1' ) c = 0xBD; /* <one-half> */
1352 break;
1353
1354 case '4':
1355 switch ( *s ) {
1356 case '1': c = 0xBC; break; /* <one-quarter> */
1357 case '3': c = 0xBE; break; /* <three-quarters> */
1358 }
1359 break;
1360
1361 case '6':
1362 switch ( *s ) {
1363 case '\'': c = 0xA9; break; /* <left-single-quotation> */
1364 case '"': c = 0xAA; break; /* <left-double-quotation> */
1365 }
1366 break;
1367
1368 case '8':
1369 switch ( *s ) {
1370 case '1': c = 0xDC; break; /* <one-eighth> */
1371 case '3': c = 0xDD; break; /* <three-eighths> */
1372 case '5': c = 0xDE; break; /* <five-eighths> */
1373 case '7': c = 0xDF; break; /* <seven-eighths> */
1374 case 'M': c = 0xD5; break; /* <eighth-note> */
1375 }
1376 break;
1377
1378 case '9':
1379 switch ( *s ) {
1380 case '\'': c = 0xB9; break; /* <right-single-quotation> */
1381 case '"': c = 0xBA; break; /* <right-double-quotation> */
1382 }
1383 break;
1384
1385 case 'A':
1386 if ( *s == 'A' ) c = -10; /* <ring-above> + <A> */
1387 break;
1388
1389 case 'a':
1390 switch ( *s ) {
1391 case '-': c = 0xE3; break; /* <femenine-ordinal-a> */
1392 case 'a': c = -10; break; /* <ring-above> + <a> */
1393 }
1394 break;
1395
1396 case 'B':
1397 if ( *s == 'B' ) c = 0xD7; /* <broken-bar> */
1398 break;
1399
1400 case 'b':
1401 if ( *s == 'N' ) c = 0xA6; /* <number-sign> */
1402 break;
1403
1404 case 'd':
1405 if ( *s == 'P' ) c = 0xA3; /* <pound-sign> */
1406 break;
1407
1408 case 'E':
1409 switch ( *s ) {
1410 case 'S': c = 0xA7; break; /* <section-sign> */
1411 case 'A': c = 0xE1; break; /* <AE> */
1412 case 'O': c = 0xEA; break; /* <OE> */
1413 }
1414 break;
1415
1416 case 'e':
1417 switch ( *s ) {
1418 case 'a': c = 0xF1; break; /* <ae> */
1419 case 'o': c = 0xFA; break; /* <oe> */
1420 case 'Y': c = 0xA5; break; /* <yen-sign> */
1421 }
1422 break;
1423
1424 case 'G':
1425 switch ( *s ) {
1426 case 'D': c = 0xB0; break; /* <degree-sign> */
1427 case 'N': c = 0xEE; break; /* <Eng> */
1428 }
1429 break;
1430
1431 case 'g':
1432 switch ( *s ) {
1433 case 'R': c = 0xD2; break; /* <registered-sign> */
1434 case 'n': c = 0xFE; break; /* <eng> */
1435 }
1436 break;
1437
1438 case 'H':
1439 if ( *s == 'T' ) c = 0xEC; /* <Thorn> */
1440 break;
1441
1442 case 'h':
1443 if ( *s == 't' ) c = 0xFC; /* <thorn> */
1444 break;
1445
1446 case 'I':
1447 switch ( *s ) {
1448 case 'P': c = 0xB6; break; /* <pilcrow-sign> */
1449 case '!': c = 0xA1; break; /* <inverted-exclamation> */
1450 case '?': c = 0xBF; break; /* <inverted-question> */
1451 }
1452 break;
1453
1454 case 'J':
1455 if ( *s == 'I' ) c = 0xE6; /* <IJ> */
1456 break;
1457
1458 case 'j':
1459 if ( *s == 'i' ) c = 0xF6; /* <ij> */
1460 break;
1461
1462 case 'k':
1463 if ( *s == 'k' ) c = 0xF0; /* <kra> */
1464 break;
1465
1466 case 'M':
1467 switch ( *s ) {
1468 case '.': c = 0xB7; break; /* <middle-dot> */
1469 case '-': c = 0xD0; break; /* <em-dash> */
1470 case 'T': c = 0xD4; break; /* <trade-mark-sign> */
1471 }
1472 break;
1473
1474 case 'm':
1475 switch ( *s ) {
1476 case '\'': /* <macron> RFC 1345 */
1477 case ' ': c = -5; break; /* <macron> */
1478 case 'O': c = 0xE0; break; /* <Ohm sign> */
1479 }
1480 break;
1481
1482 case 'n':
1483 if ( *s == '\'' ) c = 0xEF; /* <n-preceded-by-apostrophe> */
1484 break;
1485
1486 case 'O':
1487 switch ( *s ) {
1488 case 'D': c = 0xA4; break; /* <dollar-sign> */
1489 case 'N': c = 0xD6; break; /* <not-sign> */
1490 }
1491 break;
1492
1493 case 'o':
1494 switch ( *s ) {
1495 case 'C': c = 0xD3; break; /* <copyright-sign> */
1496 case '-': c = 0xEB; break; /* <masculine-ordinal-o> */
1497 }
1498 break;
1499
1500 case 'S':
1501 switch ( *s ) {
1502 case '1': c = 0xD1; break; /* <superscript-1> */
1503 case '2': c = 0xB2; break; /* <superscript-2> */
1504 case '3': c = 0xB3; break; /* <superscript-3> */
1505 case 'N': c = 0xA0; break; /* <no-break-space> */
1506 }
1507 break;
1508
1509 case 's':
1510 if ( *s == 's' ) c = 0xFB; /* <sharp-s> */
1511 break;
1512
1513 case 't':
1514 if ( *s == 'C' ) c = 0xA2; /* <cent-sign> */
1515 break;
1516
1517 case 'u':
1518 if ( *s == 'C' ) c = 0xA8; /* <currency-sign> */
1519 break;
1520
1521 case 'v':
1522 if ( *s == '-' ) c = 0xAF; /* <downwards-arrow> */
1523 break;
1524
1525 case 'X':
1526 if ( *s == '*' ) c = 0xB4; /* <multiplication-sign> */
1527 break;
1528
1529 case 'y':
1530 if ( *s == 'M' ) c = 0xB5; /* <micro-sign> */
1531 break;
1532 }
1533
1534 if ( c > 0 ) {
1535 *o++ = c;
1536 return o;
1537 } else if ( !c )
1538 return NULL;
1539
1540 /* else: c < 0 */
1541 n = -c;
1542 switch ( *s ) {
1543
1544 case 'A': c = letter_w_diacritic[n][0]; break;
1545 case 'C': c = letter_w_diacritic[n][1]; break;
1546 case 'D': c = letter_w_diacritic[n][2]; break;
1547 case 'E': c = letter_w_diacritic[n][3]; break;
1548 case 'G': c = letter_w_diacritic[n][4]; break;
1549 case 'H': c = letter_w_diacritic[n][5]; break;
1550 case 'I': c = letter_w_diacritic[n][6]; break;
1551 case 'J': c = letter_w_diacritic[n][7]; break;
1552 case 'K': c = letter_w_diacritic[n][8]; break;
1553 case 'L': c = letter_w_diacritic[n][9]; break;
1554 case 'N': c = letter_w_diacritic[n][10]; break;
1555 case 'O': c = letter_w_diacritic[n][11]; break;
1556 case 'R': c = letter_w_diacritic[n][12]; break;
1557 case 'S': c = letter_w_diacritic[n][13]; break;
1558 case 'T': c = letter_w_diacritic[n][14]; break;
1559 case 'U': c = letter_w_diacritic[n][15]; break;
1560 case 'W': c = letter_w_diacritic[n][16]; break;
1561 case 'Y': c = letter_w_diacritic[n][17]; break;
1562 case 'Z': c = letter_w_diacritic[n][18]; break;
1563
1564 case 'a': c = letter_w_diacritic[n][19]; break;
1565 case 'c': c = letter_w_diacritic[n][20]; break;
1566 case 'd': c = letter_w_diacritic[n][21]; break;
1567 case 'e': c = letter_w_diacritic[n][22]; break;
1568 case 'g': c = letter_w_diacritic[n][23]; break;
1569 case 'h': c = letter_w_diacritic[n][24]; break;
1570 case 'i': c = letter_w_diacritic[n][25]; break;
1571 case 'j': c = letter_w_diacritic[n][26]; break;
1572 case 'k': c = letter_w_diacritic[n][27]; break;
1573 case 'l': c = letter_w_diacritic[n][28]; break;
1574 case 'n': c = letter_w_diacritic[n][29]; break;
1575 case 'o': c = letter_w_diacritic[n][30]; break;
1576 case 'r': c = letter_w_diacritic[n][31]; break;
1577 case 's': c = letter_w_diacritic[n][32]; break;
1578 case 't': c = letter_w_diacritic[n][33]; break;
1579 case 'u': c = letter_w_diacritic[n][34]; break;
1580 case 'w': c = letter_w_diacritic[n][35]; break;
1581 case 'y': c = letter_w_diacritic[n][36]; break;
1582 case 'z': c = letter_w_diacritic[n][37]; break;
1583
1584 case '\'':
1585 case ' ': c = -1; break;
1586
1587 default: c = 0;
1588 }
1589
1590 if ( !c )
1591 return NULL;
1592
1593 *o++ = n + 0xC0;
1594 *o++ = ( ( (*s == ' ') || (*s == '\'') ) ? ALONE : *s );
1595 return o;
1596 }
1597
1598
1599 /* --- routine to convert from ISO 8859-n to T.61 --- */
1600
1601 int
ldap_8859_to_t61(char ** bufp,unsigned long * buflenp,int free_input)1602 ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input )
1603 {
1604 Byte *s, *oo, *o, *aux;
1605 int c;
1606 unsigned long len;
1607 Couple *cc;
1608
1609 LDAPDebug( LDAP_DEBUG_TRACE, "ldap_8859_to_t61 input length: %ld\n",
1610 *buflenp, 0, 0 );
1611
1612 len = *buflenp;
1613 s = (Byte *) *bufp;
1614
1615 if ( (o = oo = (Byte *)NSLDAPI_MALLOC( 2 * len + 64 )) == NULL ) {
1616 return( 1 );
1617 }
1618
1619 while ( (char *)s - *(char **)bufp < len ) {
1620 switch( *s >> 5 ) {
1621
1622 case 2:
1623 switch ( *s ) {
1624
1625 case '^': *o++ = 0xC3; *o++ = ALONE; s++; break;
1626
1627 case '\\':
1628 s++;
1629 if ( (c = hh_to_c( s )) != -1 ) {
1630 *o++ = c;
1631 s += 2;
1632 } else
1633 *o++ = '\\';
1634 break;
1635
1636 default: *o++ = *s++;
1637 }
1638 break;
1639
1640 case 3:
1641 switch ( *s ) {
1642
1643 case '`': *o++ = 0xC1; *o++ = ALONE; s++; break;
1644 case '~': *o++ = 0xC4; *o++ = ALONE; s++; break;
1645
1646 case '{':
1647 s++;
1648 if ( *(s + 2) == '}' ) {
1649 if ( (aux = cc_to_t61( o, s )) != NULL ) {
1650 o = aux;
1651 s += 3;
1652 } else {
1653 *o++ = '{';
1654 }
1655 } else if ( (*(s + 3) == '}') && ( (*s == 'x') || (*s == 'X') ) &&
1656 ( (c = hh_to_c( s + 1 )) != -1 ) ) {
1657 *o++ = c;
1658 s += 4;
1659 } else {
1660 *o++ = '{';
1661 }
1662 break;
1663
1664 default:
1665 *o++ = *s++;
1666 }
1667 break;
1668
1669 #if (ISO_8859 == 0)
1670 case 4: case 5: case 6: case 7:
1671 s++;
1672 break;
1673 #else
1674 case 5: case 6: case 7:
1675 # if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1676 (ISO_8859 == 4) || (ISO_8859 == 9) || (ISO_8859 == 10)
1677 if ( (*(cc = &trans_iso8859_t61[ *s - 0xA0 ])).a ) {
1678 *o++ = (*cc).a;
1679 if ( (*cc).b ) *o++ = (*cc).b;
1680 }
1681 # endif
1682 s++;
1683 break;
1684 #endif
1685
1686 default:
1687 *o++ = *s++;
1688 }
1689 }
1690
1691 len = o - oo;
1692 o = oo;
1693
1694 if ( (oo = (Byte *)NSLDAPI_REALLOC( o, len )) == NULL ) {
1695 NSLDAPI_FREE( o );
1696 return( 1 );
1697 }
1698
1699 if ( free_input ) {
1700 NSLDAPI_FREE( *bufp );
1701 }
1702 *bufp = (char *) oo;
1703 *buflenp = len;
1704 return( 0 );
1705 }
1706
1707
1708 #ifdef NOT_NEEDED_IN_LIBLDAP /* mcs@umich.edu 12 Oct 1995 */
1709 /* --- routine to convert "escaped" (\hh) characters to 8bits --- */
1710
convert_escaped_to_8bit(s)1711 void convert_escaped_to_8bit( s )
1712 char *s;
1713 {
1714 char *o = s;
1715 int c;
1716
1717 while ( *s ) {
1718 if ( *s == '\\' ) {
1719 if ( (c = hh_to_c( ++s )) != -1 ) {
1720 *o++ = c;
1721 s += 2;
1722 } else
1723 *o++ = '\\';
1724 } else
1725 *o++ = *s++;
1726 }
1727 *o = '\0';
1728 }
1729
1730 /* --- routine to convert 8bits characters to the "escaped" (\hh) form --- */
1731
convert_8bit_to_escaped(s)1732 char *convert_8bit_to_escaped( s )
1733 Byte *s;
1734 {
1735 Byte *o, *oo;
1736 Byte n;
1737
1738 if ( (o = oo = (Byte *)NSLDAPI_MALLOC( 2 * strlen( s ) + 64 )) == NULL ) {
1739 return( NULL );
1740 }
1741
1742 while ( *s ) {
1743 if ( *s < 0x80 )
1744 *o++ = *s++;
1745 else {
1746 *o++ = '\\';
1747 n = *s >> 4;
1748 *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
1749 n = *s++ & 0x0F;
1750 *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
1751 }
1752 }
1753 *o = '\0';
1754
1755 o = oo;
1756
1757 if ( (oo = (Byte *)NSLDAPI_REALLOC( o, strlen( o ) + 1 )) == NULL ) {
1758 NSLDAPI_FREE( o );
1759 return( NULL );
1760 }
1761
1762 return( (char *)oo );
1763 }
1764
1765 /* --- routine to convert from T.61 to printable characters --- */
1766
1767 /*
1768 printable characters [RFC 1488]: 'A'..'Z', 'a'..'z', '0'..'9',
1769 '\'', '(', ')', '+', ',', '-', '.', '/', ':', '?, ' '.
1770
1771 that conversion is language dependent.
1772 */
1773
1774 static Couple last_t61_printabled[32] = {
1775 {0,0}, {'A','E'}, {'D',0}, {0,0},
1776 {'H',0}, {0,0}, {'I','J'}, {'L',0},
1777 {'L',0}, {'O',0}, {'O','E'}, {0,0},
1778 {'T','H'}, {'T',0}, {'N','G'}, {'n',0},
1779 {'k',0}, {'a','e'}, {'d',0}, {'d',0},
1780 {'h',0}, {'i',0}, {'i','j'}, {'l',0},
1781 {'l',0}, {'o',0}, {'o','e'}, {'s','s'},
1782 {'t','h'}, {'t',0}, {'n','g'}, {0,0}
1783 };
1784
t61_printable(s)1785 char *t61_printable( s )
1786 Byte *s;
1787 {
1788 Byte *o, *oo;
1789 Byte n;
1790 Couple *cc;
1791
1792 if ( (o = oo = (Byte *)NSLDAPI_MALLOC( 2 * strlen( s ) + 64 )) == NULL ) {
1793 return( NULL );
1794 }
1795
1796 while ( *s ) {
1797 if ( ( (*s >= 'A') && (*s <= 'Z') ) ||
1798 ( (*s >= 'a') && (*s <= 'z') ) ||
1799 ( (*s >= '0') && (*s <= '9') ) ||
1800 ( (*s >= '\'') && (*s <= ')') ) ||
1801 ( (*s >= '+') && (*s <= '/') ) ||
1802 ( *s == '?' ) || ( *s == ' ' ) )
1803 *o++ = *s++;
1804 else {
1805 if ( *s >= 0xE0 ) {
1806 if ( (*(cc = &last_t61_printabled[ *s - 0xE0 ])).a ) {
1807 *o++ = (*cc).a;
1808 if ( (*cc).b ) *o++ = (*cc).b;
1809 }
1810 }
1811 else if ( (*s >> 4) == 0xC ) {
1812 switch ( *s ) {
1813 case 0xCA: /* ring */
1814 switch ( *(s + 1) ) {
1815 case 'A': *o++ = 'A'; *o++ = 'A'; s++; break; /* Swedish */
1816 case 'a': *o++ = 'a'; *o++ = 'a'; s++; break; /* Swedish */
1817 }
1818 break;
1819
1820 case 0xC8: /* diaeresis */
1821 switch ( *(s + 1) ) {
1822 case 'Y': *o++ = 'I'; *o++ = 'J'; s++; break; /* Dutch */
1823 case 'y': *o++ = 'i'; *o++ = 'j'; s++; break; /* Dutch */
1824 }
1825 break;
1826 }
1827 }
1828 s++;
1829 }
1830 }
1831 *o = '\0';
1832
1833 o = oo;
1834
1835 if ( (oo = (Byte *)NSLDAPI_REALLOC( o, strlen( o ) + 1 )) == NULL ) {
1836 NSLDAPI_FREE( o );
1837 return( NULL );
1838 }
1839
1840 return( (char *)oo );
1841 }
1842 #endif /* NOT_NEEDED_IN_LIBLDAP */ /* mcs@umich.edu 12 Oct 1995 */
1843
1844 #endif /* LDAP_CHARSET_8859 */
1845 #endif /* STR_TRANSLATION */
1846