summaryrefslogtreecommitdiffstats
path: root/src/lib-charset/charset-utf8-only.c
blob: e8ea810b8d08910578f1fe540894a624ae40538c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "charset-utf8-private.h"

struct charset_translation {
	normalizer_func_t *normalizer;
};

static int
utf8only_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;
}

static void utf8only_charset_to_utf8_end(struct charset_translation *t)
{
	i_free(t);
}

static void
utf8only_charset_to_utf8_reset(struct charset_translation *t ATTR_UNUSED)
{
}

static enum charset_result
utf8only_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);
}

const struct charset_utf8_vfuncs charset_utf8only = {
	.to_utf8_begin = utf8only_charset_to_utf8_begin,
	.to_utf8_end = utf8only_charset_to_utf8_end,
	.to_utf8_reset = utf8only_charset_to_utf8_reset,
	.to_utf8 = utf8only_charset_to_utf8,
};