diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 958bb54a..db0c6885 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -29,6 +29,7 @@ noinst_LTLIBRARIES = libguac_common.la noinst_HEADERS = \ guac_io.h \ guac_dot_cursor.h \ + guac_iconv.h \ guac_list.h \ guac_pointer_cursor.h \ guac_string.h @@ -36,6 +37,7 @@ noinst_HEADERS = \ libguac_common_la_SOURCES = \ guac_io.c \ guac_dot_cursor.c \ + guac_iconv.c \ guac_list.c \ guac_pointer_cursor.c \ guac_string.c diff --git a/src/common/guac_iconv.c b/src/common/guac_iconv.c new file mode 100644 index 00000000..c5721e9b --- /dev/null +++ b/src/common/guac_iconv.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2013 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "config.h" +#include "guac_iconv.h" + +void guac_iconv(guac_iconv_read* reader, char** input, int in_remaining, + guac_iconv_write* writer, char** output, int out_remaining) { + /* STUB */ +} + +int GUAC_READ_UTF8(char** input, int remaining) { + /* STUB */ + return 0; +} + + +int GUAC_READ_UTF16(char** input, int remaining) { + /* STUB */ + return 0; +} + +void GUAC_WRITE_UTF8(char** output, int remaining, int value) { + /* STUB */ +} + +void GUAC_WRITE_UTF16(char** output, int remaining, int value) { + /* STUB */ +} + diff --git a/src/common/guac_iconv.h b/src/common/guac_iconv.h new file mode 100644 index 00000000..1677541c --- /dev/null +++ b/src/common/guac_iconv.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2013 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __GUAC_COMMON_ICONV_H +#define __GUAC_COMMON_ICONV_H + +#include "config.h" + +/** + * Function which reads a character from the given string data, returning + * the Unicode codepoint read, updating the string pointer to point to the + * byte immediately after the character read. + */ +typedef int guac_iconv_read(char** input, int remaining); + +/** + * Function writes the character having the given Unicode codepoint value to + * the given string data, updating the string pointer to point to the byte + * immediately after the character written. + */ +typedef void guac_iconv_write(char** output, int remaining, int value); + +/** + * Converts characters within a given string from one encoding to another, + * as defined by the reader/writer functions specified. The input and output + * string pointers will be updated based on the number of bytes read or + * written. + * + * @param reader The reader function to use when reading the input string. + * @param input Pointer to the beginning of the input string. + * @param in_remaining The number of bytes remaining after the pointer to the + * input string. + * @param writer The writer function to use when writing the output string. + * @param output Pointer to the beginning of the output string. + * @param out_remaining The number of bytes remaining after the pointer to the + * output string. + */ +void guac_iconv(guac_iconv_read* reader, char** input, int in_remaining, + guac_iconv_write* writer, char** output, int out_remaining); + +/** + * Read function for UTF8. + */ +guac_iconv_read GUAC_READ_UTF8; + +/** + * Read function for UTF16. + */ +guac_iconv_read GUAC_READ_UTF16; + +/** + * Write function for UTF8. + */ +guac_iconv_write GUAC_WRITE_UTF8; + +/** + * Write function for UTF16. + */ +guac_iconv_write GUAC_WRITE_UTF16; + +#endif + diff --git a/tests/Makefile.am b/tests/Makefile.am index 56a51b09..9e2de545 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -39,6 +39,7 @@ test_libguac_SOURCES = \ client/buffer_pool.c \ client/layer_pool.c \ common/common_suite.c \ + common/guac_iconv.c \ common/guac_string.c \ protocol/suite.c \ protocol/base64_decode.c \ diff --git a/tests/common/common_suite.c b/tests/common/common_suite.c index 409df4eb..936ec3e8 100644 --- a/tests/common/common_suite.c +++ b/tests/common/common_suite.c @@ -45,7 +45,10 @@ int register_common_suite() { } /* Add tests */ - if (CU_add_test(suite, "guac-string", test_guac_string) == NULL) { + if ( + CU_add_test(suite, "guac-iconv", test_guac_iconv) == NULL + || CU_add_test(suite, "guac-string", test_guac_string) == NULL + ) { CU_cleanup_registry(); return CU_get_error(); } diff --git a/tests/common/common_suite.h b/tests/common/common_suite.h index 4a039be5..b078b20b 100644 --- a/tests/common/common_suite.h +++ b/tests/common/common_suite.h @@ -44,5 +44,10 @@ int register_common_suite(); */ void test_guac_string(); +/** + * Unit test for character conversion functions. + */ +void test_guac_iconv(); + #endif diff --git a/tests/common/guac_iconv.c b/tests/common/guac_iconv.c new file mode 100644 index 00000000..5dcd542b --- /dev/null +++ b/tests/common/guac_iconv.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2013 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "config.h" + +#include "common_suite.h" +#include "guac_iconv.h" + +#include +#include + +void test_guac_iconv() { + /* STUB */ +} +