stringprep.h

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

Generated on Wed Sep 13 10:20:31 2006 for libidn by  doxygen 1.4.7