xref: /titanic_41/usr/src/cmd/ssh/include/g11n.h (revision dbc3eca239c53a46b827193bc820625a1ea8a28a)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
22  * Use is subject to license terms.
23  */
24 
25 #ifndef	_G11N_H
26 #define	_G11N_H
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 
35 #include "includes.h"
36 #include <sys/types.h>
37 
38 /*
39  * Functions for language tag negotiation
40  */
41 
42 /* boolean */
43 uint_t g11n_langtag_is_default(char *langtag);
44 
45 /* return 0 if not, 1 if yes, 2 if the country is matched too */
46 uint_t g11n_langtag_matches_locale(char *langtag, char *locale);
47 
48 /* get current locale */
49 char *g11n_getlocale();
50 
51 /* get current locale */
52 void g11n_setlocale(int category, const char *locale);
53 
54 /* get list of locales - returns pointer to array of pointers to char */
55 char **g11n_getlocales();
56 
57 /* get list of langs spoken by the user, from SSH_LANGS env var */
58 char *g11n_getlangs();
59 
60 /* make a comma-separated list of language tags from list of locales */
61 char *g11n_locales2langs(char **locale_set);
62 
63 int g11n_langtag_match(char *langtag1, char *langtag2);
64 
65 /* intersect comma-separated lists of IETF language tags */
66 char *g11n_langtag_set_intersect(char *set1, char *set2);
67 
68 char *g11n_clnt_langtag_negotiate(char *clnt_langtags, char *srvr_langtags);
69 
70 char **g11n_langtag_set_locale_set_intersect(char *langtag_set,
71     char **locale_set);
72 
73 char *g11n_srvr_locale_negotiate(char *clnt_langtags, char **srvr_locales);
74 
75 /* auxiliary functions */
76 void g11n_freelist(char **list);
77 
78 /*
79  * Functions for validating ASCII and UTF-8 strings
80  *
81  * The error_str parameter is an optional pointer to a char variable
82  * where to store a string suitable for use with error() or fatal() or
83  * friends.
84  *
85  * The input string is expected to be a null-terminated string if the
86  * len parameter is given a value of 0.
87  *
88  * The return value is 0 if success, EILSEQ or EINVAL.
89  *
90  */
91 
92 uint_t g11n_validate_ascii(const char *str, uint_t len, uchar_t **error_str);
93 
94 uint_t g11n_validate_utf8(const uchar_t *str, uint_t len, uchar_t **error_str);
95 
96 /*
97  * Functions for converting to ASCII or UTF-8 from the local codeset
98  * Functions for converting from ASCII or UTF-8 to the local codeset
99  *
100  * The error_str parameter is an optional pointer to a char variable
101  * where to store a string suitable for use with error() or fatal() or
102  * friends.
103  *
104  * The err parameter is an optional pointer to an integer where 0
105  * (success) or EILSEQ or EINVAL will be stored (failure).
106  *
107  * These functions return NULL if the conversion fails.
108  *
109  */
110 
111 uchar_t *g11n_convert_from_ascii(const char *str, int *err,
112     uchar_t **error_str);
113 
114 uchar_t *g11n_convert_from_utf8(const uchar_t *str, int *err,
115     uchar_t **error_str);
116 
117 char *g11n_convert_to_ascii(const uchar_t *str, int *err,
118     uchar_t **error_str);
119 
120 uchar_t *g11n_convert_to_utf8(const uchar_t *str, int *err,
121     uchar_t **error_str);
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif /* _G11N_H */
128