summaryrefslogtreecommitdiff
path: root/src/charset/codecs/codec_impl.h
blob: 91835940b2fdc934cc319ed309f6a48053244f16 (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
/*
 * This file is part of LibParserUtils.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
 */

#ifndef parserutils_charset_codecs_codecimpl_h_
#define parserutils_charset_codecs_codecimpl_h_

#include <stdbool.h>
#include <inttypes.h>

#include <parserutils/charset/codec.h>

/**
 * Core charset codec definition; implementations extend this
 */
struct parserutils_charset_codec {
	uint16_t mibenum;			/**< MIB enum for charset */

	parserutils_charset_codec_errormode errormode;	/**< error mode */

	parserutils_alloc alloc;		/**< allocation function */
	void *alloc_pw;				/**< private word */

	struct {
		void (*destroy)(parserutils_charset_codec *codec);
		parserutils_error (*encode)(parserutils_charset_codec *codec,
				const uint8_t **source, size_t *sourcelen,
				uint8_t **dest, size_t *destlen);
		parserutils_error (*decode)(parserutils_charset_codec *codec,
				const uint8_t **source, size_t *sourcelen,
				uint8_t **dest, size_t *destlen);
		parserutils_error (*reset)(parserutils_charset_codec *codec);
	} handler; /**< Vtable for handler code */
};

/**
 * Codec factory component definition
 */
typedef struct parserutils_charset_handler {
	bool (*handles_charset)(const char *charset);
	parserutils_charset_codec *(*create)(const char *charset,
			parserutils_alloc alloc, void *pw);
} parserutils_charset_handler;

#endif