File indexing completed on 2024-05-19 04:06:44
0001 /* stringprep.h Header file for stringprep functions. -*- c -*- 0002 * Copyright (C) 2002, 2003 Simon Josefsson 0003 * 0004 * This file is part of GNU Libidn. 0005 * 0006 * GNU Libidn is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * either version 2 0010 of the License, or (at your option) any later version.1 of the License, or (at your option) any later version. 0011 * 0012 * GNU Libidn is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with GNU Libidn; if not, write to the Free Software 0019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0020 * 0021 */ 0022 0023 #ifndef _STRINGPREP_H 0024 #define _STRINGPREP_H 0025 0026 #ifdef __cplusplus 0027 extern "C" 0028 { 0029 #endif 0030 0031 #include <stddef.h> /* size_t */ 0032 0033 #include <unistd.h> /* ssize_t */ 0034 0035 #include <libidn/idn-int.h> /* my_uint32_t */ 0036 #include "qint.h" 0037 0038 #define STRINGPREP_VERSION "0.3.1" 0039 0040 /* Error codes. */ 0041 typedef enum 0042 { 0043 STRINGPREP_OK = 0, 0044 /* Stringprep errors. */ 0045 STRINGPREP_CONTAINS_UNASSIGNED = 1, 0046 STRINGPREP_CONTAINS_PROHIBITED = 2, 0047 STRINGPREP_BIDI_BOTH_L_AND_RAL = 3, 0048 STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4, 0049 STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5, 0050 /* Error in calling application. */ 0051 STRINGPREP_TOO_SMALL_BUFFER = 100, 0052 STRINGPREP_PROFILE_ERROR = 101, 0053 STRINGPREP_FLAG_ERROR = 102, 0054 STRINGPREP_UNKNOWN_PROFILE = 103, 0055 /* Internal errors. */ 0056 STRINGPREP_NFKC_FAILED = 200, 0057 STRINGPREP_MALLOC_ERROR = 201 0058 } Stringprep_rc; 0059 0060 /* Flags used when calling stringprep(). */ 0061 typedef enum 0062 { 0063 STRINGPREP_NO_NFKC = 1, 0064 STRINGPREP_NO_BIDI = 2, 0065 STRINGPREP_NO_UNASSIGNED = 4 0066 } Stringprep_profile_flags; 0067 0068 /* Steps in a stringprep profile. */ 0069 typedef enum 0070 { 0071 STRINGPREP_NFKC = 1, 0072 STRINGPREP_BIDI = 2, 0073 STRINGPREP_MAP_TABLE = 3, 0074 STRINGPREP_UNASSIGNED_TABLE = 4, 0075 STRINGPREP_PROHIBIT_TABLE = 5, 0076 STRINGPREP_BIDI_PROHIBIT_TABLE = 6, 0077 STRINGPREP_BIDI_RAL_TABLE = 7, 0078 STRINGPREP_BIDI_L_TABLE = 8 0079 } Stringprep_profile_steps; 0080 0081 #define STRINGPREP_MAX_MAP_CHARS 4 0082 0083 struct Stringprep_table_element 0084 { 0085 my_uint32_t start; 0086 my_uint32_t end; /* 0 if only one character */ 0087 my_uint32_t map[STRINGPREP_MAX_MAP_CHARS]; /* NULL if end is not 0 */ 0088 }; 0089 typedef struct Stringprep_table_element Stringprep_table_element; 0090 0091 struct Stringprep_table 0092 { 0093 Stringprep_profile_steps operation; 0094 Stringprep_profile_flags flags; 0095 Stringprep_table_element *table; 0096 char *name; 0097 }; 0098 typedef struct Stringprep_table Stringprep_profile; 0099 0100 struct Stringprep_profiles 0101 { 0102 char *name; 0103 Stringprep_profile *tables; 0104 }; 0105 typedef struct Stringprep_profiles Stringprep_profiles; 0106 0107 extern Stringprep_profiles stringprep_profiles[]; 0108 0109 /* Profiles */ 0110 extern Stringprep_table_element stringprep_rfc3454_A_1[]; 0111 extern Stringprep_table_element stringprep_rfc3454_B_1[]; 0112 extern Stringprep_table_element stringprep_rfc3454_B_2[]; 0113 extern Stringprep_table_element stringprep_rfc3454_B_3[]; 0114 extern Stringprep_table_element stringprep_rfc3454_C_1_1[]; 0115 extern Stringprep_table_element stringprep_rfc3454_C_1_2[]; 0116 extern Stringprep_table_element stringprep_rfc3454_C_2_1[]; 0117 extern Stringprep_table_element stringprep_rfc3454_C_2_2[]; 0118 extern Stringprep_table_element stringprep_rfc3454_C_3[]; 0119 extern Stringprep_table_element stringprep_rfc3454_C_4[]; 0120 extern Stringprep_table_element stringprep_rfc3454_C_5[]; 0121 extern Stringprep_table_element stringprep_rfc3454_C_6[]; 0122 extern Stringprep_table_element stringprep_rfc3454_C_7[]; 0123 extern Stringprep_table_element stringprep_rfc3454_C_8[]; 0124 extern Stringprep_table_element stringprep_rfc3454_C_9[]; 0125 extern Stringprep_table_element stringprep_rfc3454_D_1[]; 0126 extern Stringprep_table_element stringprep_rfc3454_D_2[]; 0127 0128 /* Generic (for debugging) */ 0129 0130 extern Stringprep_profile stringprep_generic[]; 0131 0132 #define stringprep_generic(in, maxlen) \ 0133 stringprep(in, maxlen, 0, stringprep_generic) 0134 0135 /* Nameprep */ 0136 0137 extern Stringprep_profile stringprep_nameprep[]; 0138 0139 #define stringprep_nameprep(in, maxlen) \ 0140 stringprep(in, maxlen, 0, stringprep_nameprep) 0141 0142 #define stringprep_nameprep_no_unassigned(in, maxlen) \ 0143 stringprep(in, maxlen, STRINGPREP_NO_UNASSIGNED, stringprep_nameprep) 0144 0145 /* SASL */ 0146 0147 extern Stringprep_profile stringprep_saslprep[]; 0148 extern Stringprep_profile stringprep_plain[]; 0149 0150 #define stringprep_plain(in, maxlen) \ 0151 stringprep(in, maxlen, 0, stringprep_plain) 0152 0153 /* Kerberos */ 0154 0155 extern Stringprep_profile stringprep_kerberos5[]; 0156 0157 #define stringprep_kerberos5(in, maxlen) \ 0158 stringprep(in, maxlen, 0, stringprep_kerberos5) 0159 0160 /* XMPP */ 0161 0162 extern Stringprep_profile stringprep_xmpp_nodeprep[]; 0163 extern Stringprep_profile stringprep_xmpp_resourceprep[]; 0164 extern Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[]; 0165 0166 #define stringprep_xmpp_nodeprep(in, maxlen) \ 0167 stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep) 0168 #define stringprep_xmpp_resourceprep(in, maxlen) \ 0169 stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep) 0170 0171 /* iSCSI */ 0172 0173 extern Stringprep_profile stringprep_iscsi[]; 0174 0175 #define stringprep_iscsi(in, maxlen) \ 0176 stringprep(in, maxlen, 0, stringprep_iscsi) 0177 0178 /* API */ 0179 0180 extern int stringprep (char *in, size_t maxlen, 0181 Stringprep_profile_flags flags, 0182 Stringprep_profile * profile); 0183 0184 extern int stringprep_profile (char *in, 0185 char **out, 0186 char *profile, 0187 Stringprep_profile_flags flags); 0188 0189 extern const char *stringprep_check_version (const char *req_version); 0190 0191 /* Utility */ 0192 0193 extern int stringprep_unichar_to_utf8 (my_uint32_t c, char *outbuf); 0194 extern my_uint32_t stringprep_utf8_to_unichar (const char *p); 0195 0196 extern my_uint32_t *stringprep_utf8_to_ucs4 (const char *str, ssize_t len, 0197 size_t * items_written); 0198 extern char *stringprep_ucs4_to_utf8 (const my_uint32_t * str, ssize_t len, 0199 size_t * items_read, 0200 size_t * items_written); 0201 0202 extern char *stringprep_utf8_nfkc_normalize (const char *str, ssize_t len); 0203 extern my_uint32_t *stringprep_ucs4_nfkc_normalize (my_uint32_t * str, 0204 ssize_t len); 0205 0206 /*extern const char *stringprep_locale_charset (void); 0207 extern char *stringprep_convert (const char *str, 0208 const char *to_codeset, 0209 const char *from_codeset); 0210 extern char *stringprep_locale_to_utf8 (const char *str); 0211 extern char *stringprep_utf8_to_locale (const char *str);*/ 0212 0213 #ifdef __cplusplus 0214 } 0215 #endif 0216 #endif /* _STRINGPREP_H */