1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef __GUAC_COMMON_ICONV_H
21 #define __GUAC_COMMON_ICONV_H
22 
23 #include "config.h"
24 
25 /**
26  * Function which reads a character from the given string data, returning
27  * the Unicode codepoint read, updating the string pointer to point to the
28  * byte immediately after the character read.
29  */
30 typedef int guac_iconv_read(const char** input, int remaining);
31 
32 /**
33  * Function writes the character having the given Unicode codepoint value to
34  * the given string data, updating the string pointer to point to the byte
35  * immediately after the character written.
36  */
37 typedef void guac_iconv_write(char** output, int remaining, int value);
38 
39 /**
40  * Converts characters within a given string from one encoding to another,
41  * as defined by the reader/writer functions specified. The input and output
42  * string pointers will be updated based on the number of bytes read or
43  * written.
44  *
45  * @param reader The reader function to use when reading the input string.
46  * @param input Pointer to the beginning of the input string.
47  * @param in_remaining The number of bytes remaining after the pointer to the
48  *                     input string.
49  * @param writer The writer function to use when writing the output string.
50  * @param output Pointer to the beginning of the output string.
51  * @param out_remaining The number of bytes remaining after the pointer to the
52  *                      output string.
53  * @return Non-zero if the NULL terminator of the input string was read and
54  *         copied into the destination string, zero otherwise.
55  */
56 int guac_iconv(guac_iconv_read* reader, const char** input, int in_remaining,
57                guac_iconv_write* writer, char** output, int out_remaining);
58 
59 /**
60  * Read function for UTF8.
61  */
62 guac_iconv_read GUAC_READ_UTF8;
63 
64 /**
65  * Read function for UTF16.
66  */
67 guac_iconv_read GUAC_READ_UTF16;
68 
69 /**
70  * Read function for CP-1252.
71  */
72 guac_iconv_read GUAC_READ_CP1252;
73 
74 /**
75  * Read function for ISO-8859-1
76  */
77 guac_iconv_read GUAC_READ_ISO8859_1;
78 
79 /**
80  * Write function for UTF8.
81  */
82 guac_iconv_write GUAC_WRITE_UTF8;
83 
84 /**
85  * Write function for UTF16.
86  */
87 guac_iconv_write GUAC_WRITE_UTF16;
88 
89 /**
90  * Write function for CP-1252.
91  */
92 guac_iconv_write GUAC_WRITE_CP1252;
93 
94 /**
95  * Write function for ISO-8859-1
96  */
97 guac_iconv_write GUAC_WRITE_ISO8859_1;
98 
99 #endif
100 
101