| 1 | /* stringprep.h Header file for stringprep functions. -*- c -*-
|
|---|
| 2 | * Copyright (C) 2002, 2003 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 |
|
|---|
| 32 | #include<qglobal.h>
|
|---|
| 33 | #ifdef Q_OS_WIN32
|
|---|
| 34 | typedef int ssize_t;
|
|---|
| 35 | #else
|
|---|
| 36 | #include <unistd.h> /* ssize_t */
|
|---|
| 37 | #endif
|
|---|
| 38 |
|
|---|
| 39 | #include <idn-int.h> /* my_uint32_t */
|
|---|
| 40 | #include "qint.h"
|
|---|
| 41 |
|
|---|
| 42 | #define STRINGPREP_VERSION "0.3.1"
|
|---|
| 43 |
|
|---|
| 44 | /* Error codes. */
|
|---|
| 45 | typedef enum
|
|---|
| 46 | {
|
|---|
| 47 | STRINGPREP_OK = 0,
|
|---|
| 48 | /* Stringprep errors. */
|
|---|
| 49 | STRINGPREP_CONTAINS_UNASSIGNED = 1,
|
|---|
| 50 | STRINGPREP_CONTAINS_PROHIBITED = 2,
|
|---|
| 51 | STRINGPREP_BIDI_BOTH_L_AND_RAL = 3,
|
|---|
| 52 | STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4,
|
|---|
| 53 | STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5,
|
|---|
| 54 | /* Error in calling application. */
|
|---|
| 55 | STRINGPREP_TOO_SMALL_BUFFER = 100,
|
|---|
| 56 | STRINGPREP_PROFILE_ERROR = 101,
|
|---|
| 57 | STRINGPREP_FLAG_ERROR = 102,
|
|---|
| 58 | STRINGPREP_UNKNOWN_PROFILE = 103,
|
|---|
| 59 | /* Internal errors. */
|
|---|
| 60 | STRINGPREP_NFKC_FAILED = 200,
|
|---|
| 61 | STRINGPREP_MALLOC_ERROR = 201
|
|---|
| 62 | } Stringprep_rc;
|
|---|
| 63 |
|
|---|
| 64 | /* Flags used when calling stringprep(). */
|
|---|
| 65 | typedef enum
|
|---|
| 66 | {
|
|---|
| 67 | STRINGPREP_NO_NFKC = 1,
|
|---|
| 68 | STRINGPREP_NO_BIDI = 2,
|
|---|
| 69 | STRINGPREP_NO_UNASSIGNED = 4
|
|---|
| 70 | } Stringprep_profile_flags;
|
|---|
| 71 |
|
|---|
| 72 | /* Steps in a stringprep profile. */
|
|---|
| 73 | typedef enum
|
|---|
| 74 | {
|
|---|
| 75 | STRINGPREP_NFKC = 1,
|
|---|
| 76 | STRINGPREP_BIDI = 2,
|
|---|
| 77 | STRINGPREP_MAP_TABLE = 3,
|
|---|
| 78 | STRINGPREP_UNASSIGNED_TABLE = 4,
|
|---|
| 79 | STRINGPREP_PROHIBIT_TABLE = 5,
|
|---|
| 80 | STRINGPREP_BIDI_PROHIBIT_TABLE = 6,
|
|---|
| 81 | STRINGPREP_BIDI_RAL_TABLE = 7,
|
|---|
| 82 | STRINGPREP_BIDI_L_TABLE = 8
|
|---|
| 83 | } Stringprep_profile_steps;
|
|---|
| 84 |
|
|---|
| 85 | #define STRINGPREP_MAX_MAP_CHARS 4
|
|---|
| 86 |
|
|---|
| 87 | struct Stringprep_table_element
|
|---|
| 88 | {
|
|---|
| 89 | my_uint32_t start;
|
|---|
| 90 | my_uint32_t end; /* 0 if only one character */
|
|---|
| 91 | my_uint32_t map[STRINGPREP_MAX_MAP_CHARS]; /* NULL if end is not 0 */
|
|---|
| 92 | };
|
|---|
| 93 | typedef struct Stringprep_table_element Stringprep_table_element;
|
|---|
| 94 |
|
|---|
| 95 | struct Stringprep_table
|
|---|
| 96 | {
|
|---|
| 97 | Stringprep_profile_steps operation;
|
|---|
| 98 | Stringprep_profile_flags flags;
|
|---|
| 99 | Stringprep_table_element *table;
|
|---|
| 100 | char *name;
|
|---|
| 101 | };
|
|---|
| 102 | typedef struct Stringprep_table Stringprep_profile;
|
|---|
| 103 |
|
|---|
| 104 | struct Stringprep_profiles
|
|---|
| 105 | {
|
|---|
| 106 | char *name;
|
|---|
| 107 | Stringprep_profile *tables;
|
|---|
| 108 | };
|
|---|
| 109 | typedef struct Stringprep_profiles Stringprep_profiles;
|
|---|
| 110 |
|
|---|
| 111 | extern Stringprep_profiles stringprep_profiles[];
|
|---|
| 112 |
|
|---|
| 113 | /* Profiles */
|
|---|
| 114 | extern Stringprep_table_element stringprep_rfc3454_A_1[];
|
|---|
| 115 | extern Stringprep_table_element stringprep_rfc3454_B_1[];
|
|---|
| 116 | extern Stringprep_table_element stringprep_rfc3454_B_2[];
|
|---|
| 117 | extern Stringprep_table_element stringprep_rfc3454_B_3[];
|
|---|
| 118 | extern Stringprep_table_element stringprep_rfc3454_C_1_1[];
|
|---|
| 119 | extern Stringprep_table_element stringprep_rfc3454_C_1_2[];
|
|---|
| 120 | extern Stringprep_table_element stringprep_rfc3454_C_2_1[];
|
|---|
| 121 | extern Stringprep_table_element stringprep_rfc3454_C_2_2[];
|
|---|
| 122 | extern Stringprep_table_element stringprep_rfc3454_C_3[];
|
|---|
| 123 | extern Stringprep_table_element stringprep_rfc3454_C_4[];
|
|---|
| 124 | extern Stringprep_table_element stringprep_rfc3454_C_5[];
|
|---|
| 125 | extern Stringprep_table_element stringprep_rfc3454_C_6[];
|
|---|
| 126 | extern Stringprep_table_element stringprep_rfc3454_C_7[];
|
|---|
| 127 | extern Stringprep_table_element stringprep_rfc3454_C_8[];
|
|---|
| 128 | extern Stringprep_table_element stringprep_rfc3454_C_9[];
|
|---|
| 129 | extern Stringprep_table_element stringprep_rfc3454_D_1[];
|
|---|
| 130 | extern Stringprep_table_element stringprep_rfc3454_D_2[];
|
|---|
| 131 |
|
|---|
| 132 | /* Generic (for debugging) */
|
|---|
| 133 |
|
|---|
| 134 | extern Stringprep_profile stringprep_generic[];
|
|---|
| 135 |
|
|---|
| 136 | #define stringprep_generic(in, maxlen) \
|
|---|
| 137 | stringprep(in, maxlen, 0, stringprep_generic)
|
|---|
| 138 |
|
|---|
| 139 | /* Nameprep */
|
|---|
| 140 |
|
|---|
| 141 | extern Stringprep_profile stringprep_nameprep[];
|
|---|
| 142 |
|
|---|
| 143 | #define stringprep_nameprep(in, maxlen) \
|
|---|
| 144 | stringprep(in, maxlen, 0, stringprep_nameprep)
|
|---|
| 145 |
|
|---|
| 146 | #define stringprep_nameprep_no_unassigned(in, maxlen) \
|
|---|
| 147 | stringprep(in, maxlen, STRINGPREP_NO_UNASSIGNED, stringprep_nameprep)
|
|---|
| 148 |
|
|---|
| 149 | /* SASL */
|
|---|
| 150 |
|
|---|
| 151 | extern Stringprep_profile stringprep_saslprep[];
|
|---|
| 152 | extern Stringprep_profile stringprep_plain[];
|
|---|
| 153 |
|
|---|
| 154 | #define stringprep_plain(in, maxlen) \
|
|---|
| 155 | stringprep(in, maxlen, 0, stringprep_plain)
|
|---|
| 156 |
|
|---|
| 157 | /* Kerberos */
|
|---|
| 158 |
|
|---|
| 159 | extern Stringprep_profile stringprep_kerberos5[];
|
|---|
| 160 |
|
|---|
| 161 | #define stringprep_kerberos5(in, maxlen) \
|
|---|
| 162 | stringprep(in, maxlen, 0, stringprep_kerberos5)
|
|---|
| 163 |
|
|---|
| 164 | /* XMPP */
|
|---|
| 165 |
|
|---|
| 166 | extern Stringprep_profile stringprep_xmpp_nodeprep[];
|
|---|
| 167 | extern Stringprep_profile stringprep_xmpp_resourceprep[];
|
|---|
| 168 | extern Stringprep_table_element stringprep_xmpp_nodeprep_prohibit[];
|
|---|
| 169 |
|
|---|
| 170 | #define stringprep_xmpp_nodeprep(in, maxlen) \
|
|---|
| 171 | stringprep(in, maxlen, 0, stringprep_xmpp_nodeprep)
|
|---|
| 172 | #define stringprep_xmpp_resourceprep(in, maxlen) \
|
|---|
| 173 | stringprep(in, maxlen, 0, stringprep_xmpp_resourceprep)
|
|---|
| 174 |
|
|---|
| 175 | /* iSCSI */
|
|---|
| 176 |
|
|---|
| 177 | extern Stringprep_profile stringprep_iscsi[];
|
|---|
| 178 |
|
|---|
| 179 | #define stringprep_iscsi(in, maxlen) \
|
|---|
| 180 | stringprep(in, maxlen, 0, stringprep_iscsi)
|
|---|
| 181 |
|
|---|
| 182 | /* API */
|
|---|
| 183 |
|
|---|
| 184 | extern int stringprep (char *in, size_t maxlen,
|
|---|
| 185 | Stringprep_profile_flags flags,
|
|---|
| 186 | Stringprep_profile * profile);
|
|---|
| 187 |
|
|---|
| 188 | extern int stringprep_profile (char *in,
|
|---|
| 189 | char **out,
|
|---|
| 190 | char *profile,
|
|---|
| 191 | Stringprep_profile_flags flags);
|
|---|
| 192 |
|
|---|
| 193 | extern const char *stringprep_check_version (const char *req_version);
|
|---|
| 194 |
|
|---|
| 195 | /* Utility */
|
|---|
| 196 |
|
|---|
| 197 | extern int stringprep_unichar_to_utf8 (my_uint32_t c, char *outbuf);
|
|---|
| 198 | extern my_uint32_t stringprep_utf8_to_unichar (const char *p);
|
|---|
| 199 |
|
|---|
| 200 | extern my_uint32_t *stringprep_utf8_to_ucs4 (const char *str, ssize_t len,
|
|---|
| 201 | size_t * items_written);
|
|---|
| 202 | extern char *stringprep_ucs4_to_utf8 (const my_uint32_t * str, ssize_t len,
|
|---|
| 203 | size_t * items_read,
|
|---|
| 204 | size_t * items_written);
|
|---|
| 205 |
|
|---|
| 206 | extern char *stringprep_utf8_nfkc_normalize (const char *str, ssize_t len);
|
|---|
| 207 | extern my_uint32_t *stringprep_ucs4_nfkc_normalize (my_uint32_t * str,
|
|---|
| 208 | ssize_t len);
|
|---|
| 209 |
|
|---|
| 210 | /*extern const char *stringprep_locale_charset (void);
|
|---|
| 211 | extern char *stringprep_convert (const char *str,
|
|---|
| 212 | const char *to_codeset,
|
|---|
| 213 | const char *from_codeset);
|
|---|
| 214 | extern char *stringprep_locale_to_utf8 (const char *str);
|
|---|
| 215 | extern char *stringprep_utf8_to_locale (const char *str);*/
|
|---|
| 216 |
|
|---|
| 217 | #ifdef __cplusplus
|
|---|
| 218 | }
|
|---|
| 219 | #endif
|
|---|
| 220 | #endif /* _STRINGPREP_H */
|
|---|