diff --git a/src/lib-charset/Makefile.am b/src/lib-charset/Makefile.am index 122d1dff1b..cb711909a4 100644 --- a/src/lib-charset/Makefile.am +++ b/src/lib-charset/Makefile.am @@ -7,7 +7,8 @@ AM_CPPFLAGS = \ libcharset_la_LIBADD = $(LTLIBICONV) libcharset_la_SOURCES = \ charset-iconv.c \ - charset-utf8.c + charset-utf8.c \ + charset-utf8-only.c headers = \ charset-utf8.h diff --git a/src/lib-charset/charset-utf8-only.c b/src/lib-charset/charset-utf8-only.c new file mode 100644 index 0000000000..1b2d940d9f --- /dev/null +++ b/src/lib-charset/charset-utf8-only.c @@ -0,0 +1,47 @@ +/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "charset-utf8.h" + +#ifndef HAVE_ICONV + +struct charset_translation { + normalizer_func_t *normalizer; +}; + +int charset_to_utf8_begin(const char *charset, normalizer_func_t *normalizer, + struct charset_translation **t_r) +{ + struct charset_translation *t; + + if (!charset_is_utf8(charset)) { + /* no support for charsets that need translation */ + return -1; + } + + t = i_new(struct charset_translation, 1); + t->normalizer = normalizer; + *t_r = t; + return 0; +} + +void charset_to_utf8_end(struct charset_translation **_t) +{ + struct charset_translation *t = *_t; + + *_t = NULL; + i_free(t); +} + +void charset_to_utf8_reset(struct charset_translation *t ATTR_UNUSED) +{ +} + +enum charset_result +charset_to_utf8(struct charset_translation *t, + const unsigned char *src, size_t *src_size, buffer_t *dest) +{ + return charset_utf8_to_utf8(t->normalizer, src, src_size, dest); +} + +#endif diff --git a/src/lib-charset/charset-utf8.c b/src/lib-charset/charset-utf8.c index 668bb45ac5..8a25eddcd5 100644 --- a/src/lib-charset/charset-utf8.c +++ b/src/lib-charset/charset-utf8.c @@ -42,49 +42,6 @@ charset_utf8_to_utf8_begin(normalizer_func_t *normalizer) return trans; } -#ifndef HAVE_ICONV - -struct charset_translation { - normalizer_func_t *normalizer; -}; - -int charset_to_utf8_begin(const char *charset, normalizer_func_t *normalizer, - struct charset_translation **t_r) -{ - struct charset_translation *t; - - if (!charset_is_utf8(charset)) { - /* no support for charsets that need translation */ - return -1; - } - - t = i_new(struct charset_translation, 1); - t->normalizer = normalizer; - *t_r = t; - return 0; -} - -void charset_to_utf8_end(struct charset_translation **_t) -{ - struct charset_translation *t = *_t; - - *_t = NULL; - i_free(t); -} - -void charset_to_utf8_reset(struct charset_translation *t ATTR_UNUSED) -{ -} - -enum charset_result -charset_to_utf8(struct charset_translation *t, - const unsigned char *src, size_t *src_size, buffer_t *dest) -{ - return charset_utf8_to_utf8(t->normalizer, src, src_size, dest); -} - -#endif - enum charset_result charset_utf8_to_utf8(normalizer_func_t *normalizer, const unsigned char *src, size_t *src_size, buffer_t *dest)