1/* $Id: filechecker.h,v 1.1 2003/06/04 00:25:37 marka Exp $ */
2/*
3 * Copyright (c) 2001 Japan Network Information Center.  All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set forth bellow.
6 *
7 * 			LICENSE TERMS AND CONDITIONS
8 *
9 * The following License Terms and Conditions apply, unless a different
10 * license is obtained from Japan Network Information Center ("JPNIC"),
11 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
12 * Chiyoda-ku, Tokyo 101-0047, Japan.
13 *
14 * 1. Use, Modification and Redistribution (including distribution of any
15 *    modified or derived work) in source and/or binary forms is permitted
16 *    under this License Terms and Conditions.
17 *
18 * 2. Redistribution of source code must retain the copyright notices as they
19 *    appear in each source code file, this License Terms and Conditions.
20 *
21 * 3. Redistribution in binary form must reproduce the Copyright Notice,
22 *    this License Terms and Conditions, in the documentation and/or other
23 *    materials provided with the distribution.  For the purposes of binary
24 *    distribution the "Copyright Notice" refers to the following language:
25 *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
26 *
27 * 4. The name of JPNIC may not be used to endorse or promote products
28 *    derived from this Software without specific prior written approval of
29 *    JPNIC.
30 *
31 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
32 *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
34 *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
35 *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#ifndef IDN_FILECHECKER_H
45#define IDN_FILECHECKER_H 1
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/*
52 * Character checker -- check if there are any characters specified
53 * by a file in the given string.
54 */
55
56#include <idn/result.h>
57
58/*
59 * Check object type.
60 */
61typedef struct idn__filechecker *idn__filechecker_t;
62
63/*
64 * Read the contents of the given file and create a context for
65 * checking.
66 *
67 * 'file' is the pathname of the file, which specifies the set of
68 * characters to be checked.  The file is a simple text file, and
69 * each line must be of the form either
70 *   <code_point>
71 * or
72 *   <code_point>-<code_point>
73 * (or comment, see below) where <code_point> is a UCS code point
74 * represented as hexadecimal string with optional prefix `U+'
75 * (ex. `0041' or `U+FEDC').
76 *
77 * The former specifies just one character (a code point, to be precise),
78 * while the latter specified a range of characters.  In the case of
79 * a character range, the first code point (before hyphen) must not be
80 * greater than the second code point (after hyphen).
81 *
82 * Lines starting with `#' are comments.
83 *
84 * If file is read with no errors, the created context is stored in
85 * '*ctxp', and 'idn_success' is returned.  Otherwise, the contents
86 * of '*ctxp' is undefined.
87 *
88 * Returns:
89 *	idn_success		-- ok.
90 *	idn_nofile		-- cannot open the specified file.
91 *	idn_nomemory		-- malloc failed.
92 *	idn_invalid_syntax	-- file format is not valid.
93 */
94extern idn_result_t
95idn__filechecker_create(const char *file, idn__filechecker_t *ctxp);
96
97/*
98 * Release memory for the specified context.
99 */
100extern void
101idn__filechecker_destroy(idn__filechecker_t ctx);
102
103/*
104 * See if the given string contains any specified characters.
105 *
106 * Check if there is any characters pecified by the context 'ctx' in
107 * the UCS4 string 'str'.  If there are none, NULL is stored in '*found'.
108 * Otherwise, the pointer to the first occurence of such character is
109 * stored in '*found'.
110 *
111 * Returns:
112 *	idn_success		-- ok.
113 */
114extern idn_result_t
115idn__filechecker_lookup(idn__filechecker_t ctx, const unsigned long *str,
116			const unsigned long **found);
117
118/*
119 * The following functions are for internal use.
120 * They are used for this module to be add to the checker module.
121 */
122extern idn_result_t
123idn__filechecker_createproc(const char *parameter, void **ctxp);
124
125extern void
126idn__filechecker_destroyproc(void *ctxp);
127
128extern idn_result_t
129idn__filechecker_lookupproc(void *ctx, const unsigned long *str,
130			    const unsigned long **found);
131
132#ifdef __cplusplus
133}
134#endif
135
136#endif /* IDN_FILECHECKER_H */
137