1 /* saslprep.c --- Internationalized SASL string processing.
2 * Copyright (C) 2002, 2003, 2004, 2005 Simon Josefsson
4 * This file is part of GNU SASL Library.
6 * GNU SASL Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * GNU SASL Library 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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License License along with GNU SASL Library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
26 # include <stringprep.h>
27 # if defined (HAVE_PR29_H) && defined (HAVE_PR29_8Z)
33 * gsasl_saslprep - prepare internationalized string
34 * @in: a UTF-8 encoded string.
35 * @flags: any SASLprep flag, e.g., %GSASL_ALLOW_UNASSIGNED.
36 * @out: on exit, contains newly allocated output string.
37 * @stringpreprc: if non-NULL, will hold precise stringprep return code.
39 * Prepare string using SASLprep. On success, the @out variable must
40 * be deallocated by the caller.
42 * Return value: Returns %GSASL_OK on success, or
43 * %GSASL_SASLPREP_ERROR on error.
48 gsasl_saslprep (const char *in
, Gsasl_saslprep_flags flags
,
49 char **out
, int *stringpreprc
)
54 rc
= stringprep_profile (in
, out
, "SASLprep",
55 (flags
& GSASL_ALLOW_UNASSIGNED
)
56 ? STRINGPREP_NO_UNASSIGNED
: 0);
61 if (rc
!= STRINGPREP_OK
)
64 return GSASL_SASLPREP_ERROR
;
67 # if defined (HAVE_PR29_8Z) && defined (HAVE_PR29_H)
68 if (pr29_8z (*out
) != PR29_SUCCESS
)
73 *stringpreprc
= STRINGPREP_NFKC_FAILED
;
75 return GSASL_SASLPREP_ERROR
;
80 size_t i
, inlen
= strlen (in
);
82 for (i
= 0; i
< inlen
; i
++)
86 return GSASL_SASLPREP_ERROR
;
89 *out
= malloc (inlen
+ 1);
91 return GSASL_MALLOC_ERROR
;