1/* $NetBSD: citrus_iconv_local.h,v 1.3 2008/02/09 14:56:20 junyoung Exp $ */
2
3/*-
4 * SPDX-License-Identifier: BSD-2-Clause
5 *
6 * Copyright (c)2003 Citrus Project,
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#ifndef _CITRUS_ICONV_LOCAL_H_
32#define _CITRUS_ICONV_LOCAL_H_
33
34#include <iconv.h>
35#include <stdbool.h>
36
37#define _CITRUS_ICONV_GETOPS_FUNC_BASE(_n_)				\
38    int _n_(struct _citrus_iconv_ops *)
39#define _CITRUS_ICONV_GETOPS_FUNC(_n_)					\
40    _CITRUS_ICONV_GETOPS_FUNC_BASE(_citrus_##_n_##_iconv_getops)
41
42#define _CITRUS_ICONV_DECLS(_m_)					\
43static int	 _citrus_##_m_##_iconv_init_shared			\
44		    (struct _citrus_iconv_shared * __restrict,		\
45	 	    const char * __restrict, const char * __restrict);	\
46static void	 _citrus_##_m_##_iconv_uninit_shared			\
47		    (struct _citrus_iconv_shared *);			\
48static int	 _citrus_##_m_##_iconv_convert				\
49		    (struct _citrus_iconv * __restrict,			\
50		    char * __restrict * __restrict,			\
51		    size_t * __restrict,				\
52		    char * __restrict * __restrict,			\
53		    size_t * __restrict outbytes,			\
54	 	    uint32_t, size_t * __restrict);			\
55static int	 _citrus_##_m_##_iconv_init_context			\
56		    (struct _citrus_iconv *);				\
57static void	 _citrus_##_m_##_iconv_uninit_context			\
58		    (struct _citrus_iconv *)
59
60
61#define _CITRUS_ICONV_DEF_OPS(_m_)					\
62extern struct _citrus_iconv_ops _citrus_##_m_##_iconv_ops;		\
63struct _citrus_iconv_ops _citrus_##_m_##_iconv_ops = {			\
64	/* io_init_shared */	&_citrus_##_m_##_iconv_init_shared,	\
65	/* io_uninit_shared */	&_citrus_##_m_##_iconv_uninit_shared,	\
66	/* io_init_context */	&_citrus_##_m_##_iconv_init_context,	\
67	/* io_uninit_context */	&_citrus_##_m_##_iconv_uninit_context,	\
68	/* io_convert */	&_citrus_##_m_##_iconv_convert		\
69}
70
71typedef _CITRUS_ICONV_GETOPS_FUNC_BASE((*_citrus_iconv_getops_t));
72typedef	int (*_citrus_iconv_init_shared_t)
73    (struct _citrus_iconv_shared * __restrict,
74    const char * __restrict, const char * __restrict);
75typedef void (*_citrus_iconv_uninit_shared_t)
76    (struct _citrus_iconv_shared *);
77typedef int (*_citrus_iconv_convert_t)
78    (struct _citrus_iconv * __restrict,
79    char *__restrict* __restrict, size_t * __restrict,
80    char * __restrict * __restrict, size_t * __restrict, uint32_t,
81    size_t * __restrict);
82typedef int (*_citrus_iconv_init_context_t)(struct _citrus_iconv *);
83typedef void (*_citrus_iconv_uninit_context_t)(struct _citrus_iconv *);
84
85struct _citrus_iconv_ops {
86	_citrus_iconv_init_shared_t	io_init_shared;
87	_citrus_iconv_uninit_shared_t	io_uninit_shared;
88	_citrus_iconv_init_context_t	io_init_context;
89	_citrus_iconv_uninit_context_t	io_uninit_context;
90	_citrus_iconv_convert_t		io_convert;
91};
92
93struct _citrus_iconv_shared {
94	struct _citrus_iconv_ops			*ci_ops;
95	void						*ci_closure;
96	_CITRUS_HASH_ENTRY(_citrus_iconv_shared)	 ci_hash_entry;
97	TAILQ_ENTRY(_citrus_iconv_shared)		 ci_tailq_entry;
98	_citrus_module_t				 ci_module;
99	unsigned int					 ci_used_count;
100	char						*ci_convname;
101	bool						 ci_discard_ilseq;
102	struct iconv_hooks				*ci_hooks;
103	bool						 ci_ilseq_invalid;
104};
105
106struct _citrus_iconv {
107	struct _citrus_iconv_shared			*cv_shared;
108	void						*cv_closure;
109};
110
111#endif
112