|
libidn
1.25
|
00001 /* stringprep.h --- Header file for stringprep functions. 00002 Copyright (C) 2002-2012 Simon Josefsson 00003 00004 This file is part of GNU Libidn. 00005 00006 GNU Libidn is free software: you can redistribute it and/or 00007 modify it under the terms of either: 00008 00009 * the GNU Lesser General Public License as published by the Free 00010 Software Foundation; either version 3 of the License, or (at 00011 your option) any later version. 00012 00013 or 00014 00015 * the GNU General Public License as published by the Free 00016 Software Foundation; either version 2 of the License, or (at 00017 your option) any later version. 00018 00019 or both in parallel, as here. 00020 00021 GNU Libidn is distributed in the hope that it will be useful, 00022 but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00024 General Public License for more details. 00025 00026 You should have received copies of the GNU General Public License and 00027 the GNU Lesser General Public License along with this program. If 00028 not, see <http://www.gnu.org/licenses/>. */ 00029 00030 #ifndef STRINGPREP_H 00031 # define STRINGPREP_H 00032 00033 # ifndef IDNAPI 00034 # if defined LIBIDN_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY 00035 # define IDNAPI __attribute__((__visibility__("default"))) 00036 # elif defined LIBIDN_BUILDING && defined _MSC_VER && ! defined LIBIDN_STATIC 00037 # define IDNAPI __declspec(dllexport) 00038 # elif defined _MSC_VER && ! defined LIBIDN_STATIC 00039 # define IDNAPI __declspec(dllimport) 00040 # else 00041 # define IDNAPI 00042 # endif 00043 # endif 00044 00045 # include <stddef.h> /* size_t */ 00046 # include <sys/types.h> /* ssize_t */ 00047 # include <idn-int.h> /* uint32_t */ 00048 00049 # ifdef __cplusplus 00050 extern "C" 00051 { 00052 # endif 00053 00054 # define STRINGPREP_VERSION "1.25" 00055 00056 /* Error codes. */ 00057 typedef enum 00058 { 00059 STRINGPREP_OK = 0, 00060 /* Stringprep errors. */ 00061 STRINGPREP_CONTAINS_UNASSIGNED = 1, 00062 STRINGPREP_CONTAINS_PROHIBITED = 2, 00063 STRINGPREP_BIDI_BOTH_L_AND_RAL = 3, 00064 STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4, 00065 STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5, 00066 /* Error in calling application. */ 00067 STRINGPREP_TOO_SMALL_BUFFER = 100, 00068 STRINGPREP_PROFILE_ERROR = 101, 00069 STRINGPREP_FLAG_ERROR = 102, 00070 STRINGPREP_UNKNOWN_PROFILE = 103, 00071 /* Internal errors. */ 00072 STRINGPREP_NFKC_FAILED = 200, 00073 STRINGPREP_MALLOC_ERROR = 201 00074 } Stringprep_rc; 00075 00076 /* Flags used when calling stringprep(). */ 00077 typedef enum 00078 { 00079 STRINGPREP_NO_NFKC = 1, 00080 STRINGPREP_NO_BIDI = 2, 00081 STRINGPREP_NO_UNASSIGNED = 4 00082 } Stringprep_profile_flags; 00083 00084 /* Steps in a stringprep profile. */ 00085 typedef enum 00086 { 00087 STRINGPREP_NFKC = 1, 00088 STRINGPREP_BIDI = 2, 00089 STRINGPREP_MAP_TABLE = 3, 00090 STRINGPREP_UNASSIGNED_TABLE = 4, 00091 STRINGPREP_PROHIBIT_TABLE = 5, 00092 STRINGPREP_BIDI_PROHIBIT_TABLE = 6, 00093 STRINGPREP_BIDI_RAL_TABLE = 7, 00094 STRINGPREP_BIDI_L_TABLE = 8 00095 } Stringprep_profile_steps; 00096 00097 # define STRINGPREP_MAX_MAP_CHARS 4 00098 00099 struct Stringprep_table_element 00100 { 00101 uint32_t start; 00102 uint32_t end; /* 0 if only one character */ 00103 uint32_t map[STRINGPREP_MAX_MAP_CHARS]; /* NULL if end is not 0 */ 00104 }; 00105 typedef struct Stringprep_table_element Stringprep_table_element; 00106 00107 struct Stringprep_table 00108 { 00109 Stringprep_profile_steps operation; 00110 Stringprep_profile_flags flags; 00111 const Stringprep_table_element *table; 00112 }; 00113 typedef struct Stringprep_table Stringprep_profile; 00114 00115 struct Stringprep_profiles 00116 { 00117 const char *name; 00118 const Stringprep_profile *tables; 00119 }; 00120 typedef struct Stringprep_profiles Stringprep_profiles; 00121 00122 extern IDNAPI const Stringprep_profiles stringprep_profiles[]; 00123 00124 /* Profiles */ 00125 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_A_1[]; 00126 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_B_1[]; 00127 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_B_2[]; 00128 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_B_3[]; 00129 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_1_1[]; 00130 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_1_2[]; 00131 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_2_1[]; 00132 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_2_2[]; 00133 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_3[]; 00134 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_4[]; 00135 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_5[]; 00136 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_6[]; 00137 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_7[]; 00138 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_8[]; 00139 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_C_9[]; 00140 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_D_1[]; 00141 extern IDNAPI const Stringprep_table_element stringprep_rfc3454_D_2[]; 00142 00143 /* Nameprep */ 00144 00145 extern IDNAPI const Stringprep_profile stringprep_nameprep[]; 00146 00147 # define stringprep_nameprep(in, maxlen) \ 00148 stringprep(in, maxlen, 0, stringprep_nameprep) 00149 00150 # define stringprep_nameprep_no_unassigned(in, maxlen) \ 00151 stringprep(in, maxlen, STRINGPREP_NO_UNASSIGNED, stringprep_nameprep) 00152 00153 /* SASL */ 00154 00155 extern IDNAPI const Stringprep_profile stringprep_saslprep[]; 00156 extern IDNAPI const Stringprep_table_element stringprep_saslprep_space_map[]; 00157 extern IDNAPI const Stringprep_profile stringprep_plain[]; 00158 extern IDNAPI const Stringprep_profile stringprep_trace[]; 00159 00160 # define stringprep_plain(in, maxlen) \ 00161 stringprep(in, maxlen, 0, stringprep_plain) 00162 00163 /* Kerberos */ 00164 00165 extern IDNAPI const Stringprep_profile stringprep_kerberos5[]; 00166 00167 # define stringprep_kerberos5(in, maxlen) \ 00168 stringprep(in, maxlen, 0, stringprep_kerberos5) 00169 00170 /* XMPP */ 00171 00172 extern IDNAPI const Stringprep_profile stringprep_xmpp_nodeprep[]; 00173 extern IDNAPI const Stringprep_profile stringprep_xmpp_resourceprep[]; 00174 extern IDNAPI const Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[]; 00175 00176 # define stringprep_xmpp_nodeprep(in, maxlen) \ 00177 stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep) 00178 # define stringprep_xmpp_resourceprep(in, maxlen) \ 00179 stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep) 00180 00181 /* iSCSI */ 00182 00183 extern IDNAPI const Stringprep_profile stringprep_iscsi[]; 00184 extern IDNAPI const Stringprep_table_element stringprep_iscsi_prohibit[]; 00185 00186 # define stringprep_iscsi(in, maxlen) \ 00187 stringprep(in, maxlen, 0, stringprep_iscsi) 00188 00189 /* API */ 00190 00191 extern IDNAPI int stringprep_4i (uint32_t * ucs4, size_t * len, 00192 size_t maxucs4len, 00193 Stringprep_profile_flags flags, 00194 const Stringprep_profile * profile); 00195 extern IDNAPI int stringprep_4zi (uint32_t * ucs4, size_t maxucs4len, 00196 Stringprep_profile_flags flags, 00197 const Stringprep_profile * profile); 00198 extern IDNAPI int stringprep (char *in, size_t maxlen, 00199 Stringprep_profile_flags flags, 00200 const Stringprep_profile * profile); 00201 00202 extern IDNAPI int stringprep_profile (const char *in, 00203 char **out, 00204 const char *profile, 00205 Stringprep_profile_flags flags); 00206 00207 extern IDNAPI const char *stringprep_strerror (Stringprep_rc rc); 00208 00209 extern IDNAPI const char *stringprep_check_version (const char 00210 *req_version); 00211 00212 /* Utility */ 00213 00214 extern IDNAPI int stringprep_unichar_to_utf8 (uint32_t c, char *outbuf); 00215 extern IDNAPI uint32_t stringprep_utf8_to_unichar (const char *p); 00216 00217 extern IDNAPI uint32_t *stringprep_utf8_to_ucs4 (const char *str, 00218 ssize_t len, 00219 size_t * items_written); 00220 extern IDNAPI char *stringprep_ucs4_to_utf8 (const uint32_t * str, 00221 ssize_t len, 00222 size_t * items_read, 00223 size_t * items_written); 00224 00225 extern IDNAPI char *stringprep_utf8_nfkc_normalize (const char *str, 00226 ssize_t len); 00227 extern IDNAPI uint32_t *stringprep_ucs4_nfkc_normalize (const uint32_t * str, 00228 ssize_t len); 00229 00230 extern IDNAPI const char *stringprep_locale_charset (void); 00231 extern IDNAPI char *stringprep_convert (const char *str, 00232 const char *to_codeset, 00233 const char *from_codeset); 00234 extern IDNAPI char *stringprep_locale_to_utf8 (const char *str); 00235 extern IDNAPI char *stringprep_utf8_to_locale (const char *str); 00236 00237 # ifdef __cplusplus 00238 } 00239 # endif 00240 00241 #endif /* STRINGPREP_H */
1.7.6.1