/* idna.c Convert to or from IDN strings.
* Copyright (C) 2002, 2003, 2004, 2011 Simon Josefsson
*
* This file is part of GNU Libidn.
*
* GNU Libidn is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* GNU Libidn is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GNU Libidn; if not, see <http://www.gnu.org/licenses/>.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <stringprep.h>
#include <punycode.h>
#include <stdint.h>
#include "idna.h"
#define DOTP(c) ((c) == 0x002E || (c) == 0x3002 || \
(c) == 0xFF0E || (c) == 0xFF61)
/* Core functions */
/**
* idna_to_ascii_4i
* @in: input array with unicode code points.
* @inlen: length of input array with unicode code points.
* @out: output zero terminated string that must have room for at
* least 63 characters plus the terminating zero.
* @flags: IDNA flags, e.g. IDNA_ALLOW_UNASSIGNED or IDNA_USE_STD3_ASCII_RULES.
*
* The ToASCII operation takes a sequence of Unicode code points that make
* up one label and transforms it into a sequence of code points in the
* ASCII range (0..7F). If ToASCII succeeds, the original sequence and the
* resulting sequence are equivalent labels.
*
* It is important to note that the ToASCII operation can fail. ToASCII
* fails if any step of it fails. If any step of the ToASCII operation
* fails on any label in a domain name, that domain name MUST NOT be used
* as an internationalized domain name. The method for deadling with this
* failure is application-specific.
*
* The inputs to ToASCII are a sequence of code points, the AllowUnassigned
* flag, and the UseSTD3ASCIIRules flag. The output of ToASCII is either a
* sequence of ASCII code points or a failure condition.
*
* ToASCII never alters a sequence of code points that are all in the ASCII
* range to begin with (although it could fail). Applying the ToASCII
* operation multiple times has exactly the same effect as applying it just
* once.
*
* Return value: Returns 0 on success, or an error code.
*/
int
idna_to_ascii_4i (const uint32_t * in, size_t inlen, char *out, int flags)
{
size_t len, outlen;
uint32_t *src; /* XXX don't need to copy data? */
int rc;
/*
* ToASCII consists of the following steps:
*
* 1. If all code points in the sequence are in the ASCII range (0..7F)
* then skip to step 3.
*/
{
size_t i;
int inasciirange;
inasciirange = 1;
for (i = 0; i < inlen; i++)
if (in[i] > 0x7F)
inasciirange = 0;
if (inasciirange)
{
src = malloc (sizeof (in[0]) * (inlen + 1));
if (src == NULL)
return IDNA_MALLOC_ERROR;
memcpy (src, in, sizeof (in[0]) * inlen);
src