Added SILC Thread Queue API
[silc.git] / lib / contrib / stringprep.h
1 /* stringprep.h --- Header file for stringprep functions.             -*- c -*-
2  * Copyright (C) 2002, 2003, 2004, 2005  Simon Josefsson
3  *
4  * This file is part of GNU Libidn.
5  *
6  * GNU Libidn is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * GNU Libidn is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with GNU Libidn; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef _STRINGPREP_H
23 #define _STRINGPREP_H
24
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29
30 #include <stddef.h>             /* size_t */
31 #include <stdlib.h>
32
33 #include "silc.h"
34
35 #ifndef uint32_t
36 #define uint32_t SilcUInt32
37 #endif
38 #ifndef ssize_t
39 #define ssize_t int
40 #endif
41 #ifndef uint16_t
42 #define uint16_t SilcUInt16
43 #endif
44 #ifndef int16_t
45 #define int16_t SilcInt16
46 #endif
47
48 #define STRINGPREP_VERSION "0.5.9"
49
50 /* Error codes. */
51   typedef enum
52   {
53     STRINGPREP_OK = 0,
54     /* Stringprep errors. */
55     STRINGPREP_CONTAINS_UNASSIGNED = 1,
56     STRINGPREP_CONTAINS_PROHIBITED = 2,
57     STRINGPREP_BIDI_BOTH_L_AND_RAL = 3,
58     STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4,
59     STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5,
60     /* Error in calling application. */
61     STRINGPREP_TOO_SMALL_BUFFER = 100,
62     STRINGPREP_PROFILE_ERROR = 101,
63     STRINGPREP_FLAG_ERROR = 102,
64     STRINGPREP_UNKNOWN_PROFILE = 103,
65     /* Internal errors. */
66     STRINGPREP_NFKC_FAILED = 200,
67     STRINGPREP_MALLOC_ERROR = 201
68   } Stringprep_rc;
69
70 /* Flags used when calling stringprep(). */
71   typedef enum
72   {
73     STRINGPREP_NO_NFKC = 1,
74     STRINGPREP_NO_BIDI = 2,
75     STRINGPREP_NO_UNASSIGNED = 4
76   } Stringprep_profile_flags;
77
78 /* Steps in a stringprep profile. */
79   typedef enum
80   {
81     STRINGPREP_NFKC = 1,
82     STRINGPREP_BIDI = 2,
83     STRINGPREP_MAP_TABLE = 3,
84     STRINGPREP_UNASSIGNED_TABLE = 4,
85     STRINGPREP_PROHIBIT_TABLE = 5,
86     STRINGPREP_BIDI_PROHIBIT_TABLE = 6,
87     STRINGPREP_BIDI_RAL_TABLE = 7,
88     STRINGPREP_BIDI_L_TABLE = 8
89   } Stringprep_profile_steps;
90
91 #define STRINGPREP_MAX_MAP_CHARS 4
92
93   struct Stringprep_table_element
94   {
95     uint32_t start;
96     uint32_t end;               /* 0 if only one character */
97     uint32_t map[STRINGPREP_MAX_MAP_CHARS];     /* NULL if end is not 0 */
98   };
99   typedef struct Stringprep_table_element Stringprep_table_element;
100
101   struct Stringprep_table
102   {
103     Stringprep_profile_steps operation;
104     Stringprep_profile_flags flags;
105     const Stringprep_table_element *table;
106   };
107   typedef struct Stringprep_table Stringprep_profile;
108
109   struct Stringprep_profiles
110   {
111     const char *name;
112     const Stringprep_profile *tables;
113   };
114   typedef struct Stringprep_profiles Stringprep_profiles;
115
116   extern const Stringprep_profiles stringprep_profiles[];
117
118 /* Profiles */
119   extern const Stringprep_table_element stringprep_rfc3454_A_1[];
120   extern const Stringprep_table_element stringprep_rfc3454_B_1[];
121   extern const Stringprep_table_element stringprep_rfc3454_B_2[];
122   extern const Stringprep_table_element stringprep_rfc3454_B_3[];
123   extern const Stringprep_table_element stringprep_rfc3454_C_1_1[];
124   extern const Stringprep_table_element stringprep_rfc3454_C_1_2[];
125   extern const Stringprep_table_element stringprep_rfc3454_C_2_1[];
126   extern const Stringprep_table_element stringprep_rfc3454_C_2_2[];
127   extern const Stringprep_table_element stringprep_rfc3454_C_3[];
128   extern const Stringprep_table_element stringprep_rfc3454_C_4[];
129   extern const Stringprep_table_element stringprep_rfc3454_C_5[];
130   extern const Stringprep_table_element stringprep_rfc3454_C_6[];
131   extern const Stringprep_table_element stringprep_rfc3454_C_7[];
132   extern const Stringprep_table_element stringprep_rfc3454_C_8[];
133   extern const Stringprep_table_element stringprep_rfc3454_C_9[];
134   extern const Stringprep_table_element stringprep_rfc3454_D_1[];
135   extern const Stringprep_table_element stringprep_rfc3454_D_2[];
136
137   extern int stringprep_4i (uint32_t * ucs4, size_t * len, size_t maxucs4len,
138                             Stringprep_profile_flags flags,
139                             const Stringprep_profile * profile);
140   extern int stringprep_4zi (uint32_t * ucs4, size_t maxucs4len,
141                              Stringprep_profile_flags flags,
142                              const Stringprep_profile * profile);
143   extern int stringprep (char *in, size_t maxlen,
144                          Stringprep_profile_flags flags,
145                          const Stringprep_profile * profile);
146
147   extern int stringprep_profile (const char *in,
148                                  char **out,
149                                  const char *profile,
150                                  Stringprep_profile_flags flags);
151
152   extern const char *stringprep_strerror (Stringprep_rc rc);
153
154   extern const char *stringprep_check_version (const char *req_version);
155
156 /* Utility */
157
158   extern int stringprep_unichar_to_utf8 (uint32_t c, char *outbuf);
159   extern uint32_t stringprep_utf8_to_unichar (const char *p);
160
161   extern uint32_t *stringprep_utf8_to_ucs4 (const char *str, int len,
162                                             size_t * items_written);
163   extern char *stringprep_ucs4_to_utf8 (const uint32_t * str, int len,
164                                         size_t * items_read,
165                                         size_t * items_written);
166
167   extern char *stringprep_utf8_nfkc_normalize (const char *str, int len);
168   extern uint32_t *stringprep_ucs4_nfkc_normalize (uint32_t * str,
169                                                    int len);
170
171   extern const char *stringprep_locale_charset (void);
172   extern char *stringprep_convert (const char *str,
173                                    const char *to_codeset,
174                                    const char *from_codeset);
175   extern char *stringprep_locale_to_utf8 (const char *str);
176   extern char *stringprep_utf8_to_locale (const char *str);
177
178 #ifdef __cplusplus
179 }
180 #endif
181 #endif                          /* _STRINGPREP_H */