1 /*
2  * ProFTPD - FTP server daemon
3  * Copyright (c) 2006-2014 The ProFTPD Project team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  *
19  * As a special exemption, The ProFTPD Project team and other respective
20  * copyright holders give permission to link this program with OpenSSL, and
21  * distribute the resulting executable, without including the source code for
22  * OpenSSL in the source distribution.
23  */
24 
25 /* UTF8/charset encoding/decoding */
26 
27 #ifndef PR_ENCODE_H
28 #define PR_ENCODE_H
29 
30 /* Translates the `in' string into the local charset using the configured
31  * encoding and returns the result.  NULL is returned if there was an error.
32  */
33 char *pr_decode_str(pool *p, const char *in, size_t inlen, size_t *outlen);
34 
35 /* Translates the `in' string from the local charset using the configured
36  * encoding and returns the result.  NULL is returned if there was an error.
37  */
38 char *pr_encode_str(pool *p, const char *in, size_t inlen, size_t *outlen);
39 
40 /* Disables runtime use of encoding (assuming NLS is supported). */
41 void pr_encode_disable_encoding(void);
42 
43 /* Enables runtime use of encoding using the specified character set (assuming
44  * NLS is supported).  Zero is returned on success, -1 if there was an
45  * issue either with the provided character set, or with the handling of
46  * that set.
47  */
48 int pr_encode_enable_encoding(const char *encoding);
49 
50 unsigned long pr_encode_get_policy(void);
51 int pr_encode_set_policy(unsigned long policy);
52 
53 /* Determines whether the Encode API will disconnect the client if the
54  * charset conversion fails, i.e. the client is using an illegal/unsupported
55  * encoding.
56  */
57 #define PR_ENCODE_POLICY_FL_REQUIRE_VALID_ENCODING		0x001
58 
59 /* Returns string describing the current charset being used. */
60 const char *pr_encode_get_charset(void);
61 
62 /* Returns string describing the local charset (as determined by environment
63  * variables and such).
64 */
65 const char *pr_encode_get_local_charset(void);
66 
67 /* Returns string describing the current character set (or UTF8) encoding
68  * being used.  NULL is returned if no encoding is currently in effect.
69  */
70 const char *pr_encode_get_encoding(void);
71 
72 /* Convenience function which returns TRUE if the given encoding is UTF8,
73  * FALSE otherwise.  (There are multiple different strings for denoting
74  * UTF8, and callers should not need to have to know about those different
75  * formulations.)
76  *
77  * Note that -1 will be returned if there was an error (e.g. NULL arguments).
78  */
79 int pr_encode_is_utf8(const char *codeset);
80 
81 /* Convenience function which returns TRUE if the current encoding
82  * (i.e. from pr_encode_get_encoding()) supports the Telnet IAC (0xFF)
83  * character, FALSE otherwise.
84  *
85  * Some character sets (e.g. CP1251 for Cyrillic character sets) use that
86  * value for a character.  This breaks RFC959 compliance, unfortunately.
87  */
88 int pr_encode_supports_telnet_iac(void);
89 
90 /* Change the local charset AND encoding being used. */
91 int pr_encode_set_charset_encoding(const char *charset, const char *encoding);
92 
93 /* Internal use only. */
94 int encode_init(void);
95 int encode_free(void);
96 
97 #endif /* PR_ENCODE_H */
98