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