Add unmodified doxygen configuration file, for future "diff"s.
[libidn.git] / idna.c
blob13c97174077cd9ac1e517619d060f63120c1ae07
1 /* idna.c Convert to or from IDN strings.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of GNU Libidn.
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.
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.
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
22 #include "internal.h"
24 /**
25 * idna_to_ascii
26 * @in: input array with unicode code points.
27 * @inlen: length of input array with unicode code points.
28 * @out: output zero terminated string that must have room for at
29 * least 63 characters plus the terminating zero.
30 * @allowunassigned: whether to allow unassigned code points.
31 * @usestd3asciirules: whether to check input for STD3 compliance.
33 * The ToASCII operation takes a sequence of Unicode code points that make
34 * up one label and transforms it into a sequence of code points in the
35 * ASCII range (0..7F). If ToASCII succeeds, the original sequence and the
36 * resulting sequence are equivalent labels.
38 * It is important to note that the ToASCII operation can fail. ToASCII
39 * fails if any step of it fails. If any step of the ToASCII operation
40 * fails on any label in a domain name, that domain name MUST NOT be used
41 * as an internationalized domain name. The method for deadling with this
42 * failure is application-specific.
44 * The inputs to ToASCII are a sequence of code points, the AllowUnassigned
45 * flag, and the UseSTD3ASCIIRules flag. The output of ToASCII is either a
46 * sequence of ASCII code points or a failure condition.
48 * ToASCII never alters a sequence of code points that are all in the ASCII
49 * range to begin with (although it could fail). Applying the ToASCII
50 * operation multiple times has exactly the same effect as applying it just
51 * once.
53 * Return value: Returns 0 on success, or an error code.
55 int
56 idna_to_ascii (const unsigned long *in, size_t inlen,
57 char *out, int allowunassigned, int usestd3asciirules)
59 size_t len, outlen;
60 unsigned long *src; /* XXX don't need to copy data? */
61 int rc;
65 * ToASCII consists of the following steps:
67 * 1. If all code points in the sequence are in the ASCII range (0..7F)
68 * then skip to step 3.
72 size_t i;
73 int inasciirange;
75 inasciirange = 1;
76 for (i = 0; in[i]; i++)
77 if (in[i] > 0x7F)
78 inasciirange = 0;
79 if (inasciirange)
81 src = malloc (sizeof (in[0]) * (inlen + 1));
82 if (src == NULL)
83 return IDNA_MALLOC_ERROR;
85 memcpy (src, in, sizeof (in[0]) * inlen);
86 src[inlen] = 0;
88 goto step3;
93 * 2. Perform the steps specified in [NAMEPREP] and fail if there is
94 * an error. The AllowUnassigned flag is used in [NAMEPREP].
98 char *p;
100 p = stringprep_ucs4_to_utf8 (in, inlen, NULL, NULL);
101 if (p == NULL)
102 return IDNA_MALLOC_ERROR;
104 len = strlen(p);
107 len = 2 * len + 10; /* XXX better guess? */
108 p = realloc (p, len);
109 if (p == NULL)
110 return IDNA_MALLOC_ERROR;
112 if (allowunassigned)
113 rc = stringprep_nameprep (p, len);
114 else
115 rc = stringprep_nameprep_no_unassigned (p, len);
117 while (rc == STRINGPREP_TOO_SMALL_BUFFER);
119 if (rc != STRINGPREP_OK)
121 free(p);
122 return IDNA_STRINGPREP_ERROR;
125 src = stringprep_utf8_to_ucs4 (p, -1, NULL);
127 free(p);
130 step3:
132 * 3. If the UseSTD3ASCIIRules flag is set, then perform these checks:
134 * (a) Verify the absence of non-LDH ASCII code points; that is,
135 * the absence of 0..2C, 2E..2F, 3A..40, 5B..60, and 7B..7F.
137 * (b) Verify the absence of leading and trailing hyphen-minus;
138 * that is, the absence of U+002D at the beginning and end of
139 * the sequence.
142 if (usestd3asciirules)
144 size_t i;
146 for (i = 0; src[i]; i++)
147 if (src[i] <= 0x2C || src[i] == 0x2E || src[i] == 0x2F ||
148 (src[i] >= 0x3A && src[i] <= 0x40) ||
149 (src[i] >= 0x5B && src[i] <= 0x60) ||
150 (src[i] >= 0x7B && src[i] <= 0x7F))
152 free(src);
153 return IDNA_CONTAINS_LDH;
156 if (src[0] == 0x002D || (i > 0 && src[i - 1] == 0x002D))
158 free(src);
159 return IDNA_CONTAINS_MINUS;
164 * 4. If all code points in the sequence are in the ASCII range
165 * (0..7F), then skip to step 8.
169 size_t i;
170 int inasciirange;
172 inasciirange = 1;
173 for (i = 0; src[i]; i++)
175 if (src[i] > 0x7F)
176 inasciirange = 0;
177 /* copy string to output buffer if we are about to skip to step8 */
178 if (i < 64)
179 out[i] = src[i];
181 if (i < 64)
182 out[i] = '\0';
183 if (inasciirange)
184 goto step8;
188 * 5. Verify that the sequence does NOT begin with the ACE prefix.
193 size_t i;
194 int match;
196 match = 1;
197 for (i = 0; match && i < strlen (IDNA_ACE_PREFIX); i++)
198 if (((unsigned long)IDNA_ACE_PREFIX[i] & 0xFF) != src[i])
199 match = 0;
200 if (match)
202 free(src);
203 return IDNA_CONTAINS_ACE_PREFIX;
208 * 6. Encode the sequence using the encoding algorithm in [PUNYCODE]
209 * and fail if there is an error.
211 for (len = 0; src[len]; len++)
213 src[len] = '\0';
214 outlen = 63 - strlen (IDNA_ACE_PREFIX);
215 rc = punycode_encode (len, src, NULL,
216 &outlen, &out[strlen (IDNA_ACE_PREFIX)]);
217 free(src);
218 if (rc != PUNYCODE_SUCCESS)
219 return IDNA_PUNYCODE_ERROR;
220 out[strlen (IDNA_ACE_PREFIX) + outlen] = '\0';
223 * 7. Prepend the ACE prefix.
226 memcpy (out, IDNA_ACE_PREFIX, strlen (IDNA_ACE_PREFIX));
229 * 8. Verify that the number of code points is in the range 1 to 63
230 * inclusive.
233 step8:
234 if (strlen (out) < 1 || strlen (out) > 63)
235 return IDNA_INVALID_LENGTH;
237 return IDNA_SUCCESS;
240 static int
241 idna_to_unicode_internal (const unsigned long *in, size_t inlen,
242 unsigned long *out, size_t * outlen,
243 int allowunassigned, int usestd3asciirules,
244 char *utf8in, size_t utf8len)
246 int rc;
247 char tmpout[64];
250 * 1. If all code points in the sequence are in the ASCII range (0..7F)
251 * then skip to step 3.
255 size_t i;
256 int inasciirange;
258 inasciirange = 1;
259 for (i = 0; in[i]; i++)
260 if (in[i] > 0x7F)
261 inasciirange = 0;
262 if (inasciirange)
263 goto step3;
267 * 2. Perform the steps specified in [NAMEPREP] and fail if there is an
268 * error. (If step 3 of ToASCII is also performed here, it will not
269 * affect the overall behavior of ToUnicode, but it is not
270 * necessary.) The AllowUnassigned flag is used in [NAMEPREP].
273 if (allowunassigned)
274 rc = stringprep_nameprep (utf8in, utf8len);
275 else
276 rc = stringprep_nameprep_no_unassigned (utf8in, utf8len);
278 if (rc != STRINGPREP_OK)
279 return IDNA_STRINGPREP_ERROR;
281 /* 3. Verify that the sequence begins with the ACE prefix, and save a
282 * copy of the sequence.
285 step3:
286 if (memcmp (IDNA_ACE_PREFIX, utf8in, strlen (IDNA_ACE_PREFIX)) != 0)
287 return IDNA_NO_ACE_PREFIX;
289 /* 4. Remove the ACE prefix.
292 memmove (utf8in, &utf8in[strlen (IDNA_ACE_PREFIX)],
293 strlen (utf8in) - strlen (IDNA_ACE_PREFIX) + 1);
295 /* 5. Decode the sequence using the decoding algorithm in [PUNYCODE]
296 * and fail if there is an error. Save a copy of the result of
297 * this step.
300 (*outlen)--; /* reserve one for the zero */
302 rc = punycode_decode (strlen (utf8in), utf8in, outlen, out, NULL);
303 if (rc != PUNYCODE_SUCCESS)
304 return IDNA_PUNYCODE_ERROR;
306 out[*outlen] = 0; /* add zero */
308 /* 6. Apply ToASCII.
311 rc = idna_to_ascii (out, *outlen, tmpout,
312 allowunassigned, usestd3asciirules);
313 if (rc != IDNA_SUCCESS)
314 return rc;
316 /* 7. Verify that the result of step 6 matches the saved copy from
317 * step 3, using a case-insensitive ASCII comparison.
320 if (strcasecmp (utf8in, tmpout + strlen (IDNA_ACE_PREFIX)) != 0)
321 return IDNA_ROUNDTRIP_VERIFY_ERROR;
323 /* 8. Return the saved copy from step 5.
326 return IDNA_SUCCESS;
330 * idna_to_unicode
331 * @in: input array with unicode code points.
332 * @inlen: length of input array with unicode code points.
333 * @out: output array with unicode code points.
334 * @outlen: on input, maximum size of output array with unicode code points,
335 * on exit, actual size of output array with unicode code points.
336 * @allowunassigned: whether to allow unassigned code points.
337 * @usestd3asciirules: whether to check input for STD3 compliance.
339 * The ToUnicode operation takes a sequence of Unicode code points
340 * that make up one label and returns a sequence of Unicode code
341 * points. If the input sequence is a label in ACE form, then the
342 * result is an equivalent internationalized label that is not in ACE
343 * form, otherwise the original sequence is returned unaltered.
345 * ToUnicode never fails. If any step fails, then the original input
346 * sequence is returned immediately in that step.
348 * The ToUnicode output never contains more code points than its
349 * input. Note that the number of octets needed to represent a
350 * sequence of code points depends on the particular character
351 * encoding used.
353 * The inputs to ToUnicode are a sequence of code points, the
354 * AllowUnassigned flag, and the UseSTD3ASCIIRules flag. The output of
355 * ToUnicode is always a sequence of Unicode code points.
357 * Return value: Returns error condition, but it must only be used for
358 * debugging purposes. The output buffer is always
359 * guaranteed to contain the correct data according to
360 * the specification (sans malloc induced errors). NB!
361 * This means that you normally ignore the return code
362 * from this function, as checking it means breaking the
363 * standard.
366 idna_to_unicode (const unsigned long *in, size_t inlen,
367 unsigned long *out, size_t * outlen,
368 int allowunassigned, int usestd3asciirules)
370 int rc;
371 size_t outlensave = *outlen;
372 char *p;
374 p = stringprep_ucs4_to_utf8 (in, inlen, NULL, NULL);
375 if (p == NULL)
376 return IDNA_MALLOC_ERROR;
378 p = realloc (p, BUFSIZ);
379 if (p == NULL)
380 return IDNA_MALLOC_ERROR;
382 rc = idna_to_unicode_internal (in, inlen, out, outlen,
383 allowunassigned, usestd3asciirules,
384 p, BUFSIZ);
385 if (rc != IDNA_SUCCESS)
387 memcpy (out, in, sizeof (in[0]) * (inlen < outlensave ?
388 inlen : outlensave));
389 *outlen = inlen;
392 free (p);
394 return rc;
398 * idna_to_ascii_from_ucs4:
399 * @input: zero terminated input Unicode string.
400 * @output: pointer to newly allocated output string.
401 * @allowunassigned: whether to allow unassigned code points.
402 * @usestd3asciirules: whether to check input for STD3 compliance.
404 * Convert UCS-4 domain name to ASCII string. The domain name may
405 * contain several labels, separated by dots. The output buffer must
406 * be deallocated by the caller.
408 * Return value: Returns IDNA_SUCCESS on success, or error code.
411 idna_to_ascii_from_ucs4 (const unsigned long *input, char **output,
412 int allowunassigned, int usestd3asciirules)
414 const unsigned long *start = input;
415 const unsigned long *end = input;
416 char buf[64];
417 char *out = NULL;
418 int rc;
420 *output = NULL;
424 end = start;
426 /* 1) Whenever dots are used as label separators, the following
427 characters MUST be recognized as dots: U+002E (full stop),
428 U+3002 (ideographic full stop), U+FF0E (fullwidth full stop),
429 U+FF61 (halfwidth ideographic full stop). */
430 for (; *end &&
431 *end != 0x002E &&
432 *end != 0x3002 && *end != 0xFF0E && *end != 0xFF61; end++)
435 rc = idna_to_ascii (start, end - start, buf,
436 allowunassigned, usestd3asciirules);
437 if (rc != IDNA_SUCCESS)
438 return rc;
440 if (out)
442 out = realloc (out, strlen (out) + 1 + strlen (buf) + 1);
443 if (!out)
444 return IDNA_MALLOC_ERROR;
445 strcat (out, ".");
446 strcat (out, buf);
448 else
450 out = strdup (buf);
451 if (!out)
452 return IDNA_MALLOC_ERROR;
455 start = end + 1;
457 while (*end);
459 *output = out;
461 return IDNA_SUCCESS;
465 * idna_ucs4_to_ace:
466 * @input: zero terminated input Unicode string.
467 * @output: pointer to newly allocated output string.
469 * Convert UCS-4 domain name to ASCII string. The AllowUnassigned
470 * flag is false and std3asciirules flag is false. The domain name
471 * may contain several labels, separated by dots. The output buffer
472 * must be deallocated by the caller.
474 * This function is deprecated in favor of idna_to_ascii_from_ucs4()
475 * and will be removed in future versions.
477 * Return value: Returns IDNA_SUCCESS on success, or error code.
480 idna_ucs4_to_ace (const unsigned long *input, char **output)
482 return idna_to_ascii_from_ucs4 (input, output, 0, 0);
486 * idna_to_ascii_from_utf8:
487 * @input: zero terminated input UTF-8 string.
488 * @output: pointer to newly allocated output string.
489 * @allowunassigned: whether to allow unassigned code points.
490 * @usestd3asciirules: whether to check input for STD3 compliance.
492 * Convert UTF-8 domain name to ASCII string. The domain name may
493 * contain several labels, separated by dots. The output buffer must
494 * be deallocated by the caller.
496 * Return value: Returns IDNA_SUCCESS on success, or error code.
499 idna_to_ascii_from_utf8 (const char *input, char **output,
500 int allowunassigned, int usestd3asciirules)
502 unsigned long *ucs4;
503 size_t ucs4len;
504 int rc;
506 ucs4 = stringprep_utf8_to_ucs4 (input, -1, &ucs4len);
507 if (!ucs4)
508 return IDNA_ICONV_ERROR;
510 rc = idna_to_ascii_from_ucs4 (ucs4, output,
511 allowunassigned, usestd3asciirules);
512 free (ucs4);
514 return rc;
518 * idna_utf8_to_ace:
519 * @input: zero terminated input UTF-8 string.
520 * @output: pointer to newly allocated output string.
522 * Convert UTF-8 domain name to ASCII string. The AllowUnassigned
523 * flag is false and std3asciirules flag is false. The domain name
524 * may contain several labels, separated by dots. The output buffer
525 * must be deallocated by the caller.
527 * This function is deprecated in favor of idna_to_ascii_from_utf8()
528 * and will be removed in future versions.
530 * Return value: Returns IDNA_SUCCESS on success, or error code.
533 idna_utf8_to_ace (const char *input, char **output)
535 return idna_to_ascii_from_utf8 (input, output, 0, 0);
539 * idna_to_ascii_from_locale:
540 * @input: zero terminated input UTF-8 string.
541 * @output: pointer to newly allocated output string.
542 * @allowunassigned: whether to allow unassigned code points.
543 * @usestd3asciirules: whether to check input for STD3 compliance.
545 * Convert domain name in the locale's encoding to ASCII string. The
546 * domain name may contain several labels, separated by dots. The
547 * output buffer must be deallocated by the caller.
549 * Return value: Returns IDNA_SUCCESS on success, or error code.
552 idna_to_ascii_from_locale (const char *input, char **output,
553 int allowunassigned, int usestd3asciirules)
555 char *utf8;
556 int rc;
558 utf8 = stringprep_locale_to_utf8 (input);
559 if (!utf8)
560 return IDNA_ICONV_ERROR;
562 rc = idna_to_ascii_from_utf8 (utf8, output,
563 allowunassigned, usestd3asciirules);
564 free (utf8);
566 return rc;
570 * idna_locale_to_ace:
571 * @input: zero terminated input UTF-8 string.
572 * @output: pointer to newly allocated output string.
574 * Convert domain name in the locale's encoding to ASCII string. The
575 * AllowUnassigned flag is false and std3asciirules flag is false.
576 * The domain name may contain several labels, separated by dots. The
577 * output buffer must be deallocated by the caller.
579 * This function is deprecated in favor of idna_to_ascii_from_locale()
580 * and will be removed in future versions.
582 * Return value: Returns IDNA_SUCCESS on success, or error code.
585 idna_locale_to_ace (const char *input, char **output)
587 return idna_to_ascii_from_locale (input, output, 0, 0);
591 * idna_to_unicode_ucs4_from_ucs4:
592 * @input: zero-terminated Unicode string.
593 * @output: pointer to newly allocated output Unicode string.
594 * @allowunassigned: whether to allow unassigned code points.
595 * @usestd3asciirules: whether to check input for STD3 compliance.
597 * Convert possibly ACE encoded domain name in UCS-4 format into a
598 * UCS-4 string. The domain name may contain several labels,
599 * separated by dots. The output buffer must be deallocated by the
600 * caller.
602 * Return value: Returns IDNA_SUCCESS on success, or error code.
605 idna_to_unicode_ucs4_from_ucs4 (const unsigned long *input,
606 unsigned long **output,
607 int allowunassigned, int usestd3asciirules)
609 const unsigned long *start = input;
610 const unsigned long *end = input;
611 unsigned long *buf;
612 size_t buflen;
613 unsigned long *out = NULL;
614 size_t outlen = 0;
615 int rc;
617 *output = NULL;
621 end = start;
623 /* 1) Whenever dots are used as label separators, the following
624 characters MUST be recognized as dots: U+002E (full stop),
625 U+3002 (ideographic full stop), U+FF0E (fullwidth full stop),
626 U+FF61 (halfwidth ideographic full stop). */
627 for (; *end &&
628 *end != 0x002E &&
629 *end != 0x3002 && *end != 0xFF0E && *end != 0xFF61; end++)
632 buflen = end - start;
633 buf = malloc (sizeof (buf[0]) * (buflen + 1));
634 if (!buf)
635 return IDNA_MALLOC_ERROR;
637 rc = idna_to_unicode (start, end - start, buf, &buflen,
638 allowunassigned, usestd3asciirules);
639 /* don't check rc as per specification! */
641 if (out)
643 out = realloc (out, sizeof (out[0]) * (outlen + 1 + buflen + 1));
644 if (!out)
645 return IDNA_MALLOC_ERROR;
646 out[outlen++] = 0x002E; /* '.' (full stop) */
647 memcpy (out + outlen, buf, sizeof (buf[0]) * buflen);
648 outlen += buflen;
649 out[outlen] = 0x0;
650 free (buf);
652 else
654 out = buf;
655 outlen = buflen;
656 out[outlen] = 0x0;
659 start = end + 1;
661 while (*end);
663 *output = out;
665 return IDNA_SUCCESS;
669 * idna_ucs4ace_to_ucs4:
670 * @input: zero-terminated Unicode string.
671 * @output: pointer to newly allocated output Unicode string.
673 * Convert possibly ACE encoded domain name in UCS-4 format into a
674 * UCS-4 string. The AllowUnassigned flag is false and std3asciirules
675 * flag is false. The domain name may contain several labels,
676 * separated by dots. The output buffer must be deallocated by the
677 * caller.
679 * This function is deprecated in favor of
680 * idna_to_unicode_ucs4_from_ucs4() and will be removed in future
681 * versions.
683 * Return value: Returns IDNA_SUCCESS on success, or error code.
686 idna_ucs4ace_to_ucs4 (const unsigned long *input, unsigned long **output)
688 return idna_to_unicode_ucs4_from_ucs4 (input, output, 0, 0);
692 * idna_to_unicode_ucs4_from_utf8:
693 * @input: zero-terminated UTF-8 string.
694 * @output: pointer to newly allocated output Unicode string.
695 * @allowunassigned: whether to allow unassigned code points.
696 * @usestd3asciirules: whether to check input for STD3 compliance.
698 * Convert possibly ACE encoded domain name in UTF-8 format into a
699 * UCS-4 string. The domain name may contain several labels,
700 * separated by dots. The output buffer must be deallocated by the
701 * caller.
703 * Return value: Returns IDNA_SUCCESS on success, or error code.
706 idna_to_unicode_ucs4_from_utf8 (const char *input, unsigned long **output,
707 int allowunassigned, int usestd3asciirules)
709 unsigned long *ucs4;
710 size_t ucs4len;
711 int rc;
713 ucs4 = stringprep_utf8_to_ucs4 (input, -1, &ucs4len);
714 if (!ucs4)
715 return IDNA_ICONV_ERROR;
717 rc = idna_to_unicode_ucs4_from_ucs4 (ucs4, output,
718 allowunassigned, usestd3asciirules);
719 free (ucs4);
721 return rc;
725 * idna_utf8ace_to_ucs4:
726 * @input: zero-terminated UTF-8 string.
727 * @output: pointer to newly allocated output Unicode string.
729 * Convert possibly ACE encoded domain name in UTF-8 format into a
730 * UCS-4 string. The AllowUnassigned flag is false and std3asciirules
731 * flag is false. The domain name may contain several labels,
732 * separated by dots. The output buffer must be deallocated by the
733 * caller.
735 * This function is deprecated in favor of
736 * idna_to_unicode_ucs4_from_utf8() and will be removed in future
737 * versions.
739 * Return value: Returns IDNA_SUCCESS on success, or error code.
742 idna_utf8ace_to_ucs4 (const char *input, unsigned long **output)
744 return idna_to_unicode_ucs4_from_utf8 (input, output, 0, 0);
748 * idna_to_unicode_utf8_from_utf8:
749 * @input: zero-terminated UTF-8 string.
750 * @output: pointer to newly allocated output UTF-8 string.
751 * @allowunassigned: whether to allow unassigned code points.
752 * @usestd3asciirules: whether to check input for STD3 compliance.
754 * Convert possibly ACE encoded domain name in UTF-8 format into a
755 * UTF-8 string. The domain name may contain several labels,
756 * separated by dots. The output buffer must be deallocated by the
757 * caller.
759 * Return value: Returns IDNA_SUCCESS on success, or error code.
762 idna_to_unicode_utf8_from_utf8 (const char *input, char **output,
763 int allowunassigned, int usestd3asciirules)
765 unsigned long *ucs4;
766 int rc;
768 rc = idna_to_unicode_ucs4_from_utf8 (input, &ucs4,
769 allowunassigned, usestd3asciirules);
770 *output = stringprep_ucs4_to_utf8 (ucs4, -1, NULL, NULL);
771 free (ucs4);
773 if (!*output)
774 return IDNA_ICONV_ERROR;
776 return rc;
780 * idna_utf8ace_to_utf8:
781 * @input: zero-terminated UTF-8 string.
782 * @output: pointer to newly allocated output UTF-8 string.
784 * Convert possibly ACE encoded domain name in UTF-8 format into a
785 * UTF-8 string. The AllowUnassigned flag is false and std3asciirules
786 * flag is false. The domain name may contain several labels,
787 * separated by dots. The output buffer must be deallocated by the
788 * caller.
790 * This function is deprecated in favor of
791 * idna_to_unicode_utf8_from_utf8() and will be removed in future
792 * versions.
794 * Return value: Returns IDNA_SUCCESS on success, or error code.
797 idna_utf8ace_to_utf8 (const char *input, char **output)
799 return idna_to_unicode_utf8_from_utf8 (input, output, 0, 0);
803 * idna_to_unicode_locale_from_utf8:
804 * @input: zero-terminated UTF-8 string.
805 * @output: pointer to newly allocated output string encoded in the
806 * current locale's character set.
807 * @allowunassigned: whether to allow unassigned code points.
808 * @usestd3asciirules: whether to check input for STD3 compliance.
810 * Convert possibly ACE encoded domain name in UTF-8 format into a
811 * string encoded in the current locale's character set. The
812 * The domain name may contain several labels, separated by dots. The
813 * output buffer must be deallocated by the caller.
815 * Return value: Returns IDNA_SUCCESS on success, or error code.
818 idna_to_unicode_locale_from_utf8 (const char *input, char **output,
819 int allowunassigned, int usestd3asciirules)
821 char *utf8;
822 int rc;
824 rc = idna_to_unicode_utf8_from_utf8 (input, &utf8,
825 allowunassigned, usestd3asciirules);
826 *output = stringprep_utf8_to_locale (utf8);
827 free (utf8);
829 if (!*output)
830 return IDNA_ICONV_ERROR;
832 return rc;
836 * idna_utf8ace_to_locale:
837 * @input: zero-terminated UTF-8 string.
838 * @output: pointer to newly allocated output string encoded in the
839 * current locale's character set.
841 * Convert possibly ACE encoded domain name in UTF-8 format into a
842 * string encoded in the current locale's character set. The
843 * AllowUnassigned flag is false and std3asciirules flag is false.
844 * The domain name may contain several labels, separated by dots. The
845 * output buffer must be deallocated by the caller.
847 * This function is deprecated in favor of
848 * idna_to_unicode_locale_from_utf8() and will be removed in future
849 * versions.
851 * Return value: Returns IDNA_SUCCESS on success, or error code.
854 idna_utf8ace_to_locale (const char *input, char **output)
856 return idna_to_unicode_locale_from_utf8 (input, output, 0, 0);
860 * idna_to_unicode_locale_from_locale:
861 * @input: zero-terminated string encoded in the current locale's
862 * character set.
863 * @output: pointer to newly allocated output string encoded in the
864 * current locale's character set.
865 * @allowunassigned: whether to allow unassigned code points.
866 * @usestd3asciirules: whether to check input for STD3 compliance.
868 * Convert possibly ACE encoded domain name in the locale's character
869 * set into a string encoded in the current locale's character set.
870 * The domain name may contain several labels, separated by dots. The
871 * output buffer must be deallocated by the caller.
873 * Return value: Returns IDNA_SUCCESS on success, or error code.
876 idna_to_unicode_locale_from_locale (const char *input, char **output,
877 int allowunassigned,
878 int usestd3asciirules)
880 char *utf8;
881 int rc;
883 utf8 = stringprep_locale_to_utf8 (input);
884 if (!utf8)
885 return IDNA_ICONV_ERROR;
887 rc = idna_to_unicode_locale_from_utf8 (utf8, output,
888 allowunassigned, usestd3asciirules);
889 free (utf8);
891 return rc;
895 * idna_localeace_to_locale:
896 * @input: zero-terminated string encoded in the current locale's
897 * character set.
898 * @output: pointer to newly allocated output string encoded in the
899 * current locale's character set.
901 * Convert possibly ACE encoded domain name in the locale's character
902 * set into a string encoded in the current locale's character set.
903 * The AllowUnassigned flag is false and std3asciirules flag is false.
904 * The domain name may contain several labels, separated by dots. The
905 * output buffer must be deallocated by the caller.
907 * This function is deprecated in favor of
908 * idna_to_unicode_locale_from_locale() and will be removed in future
909 * versions.
911 * Return value: Returns IDNA_SUCCESS on success, or error code.
914 idna_localeace_to_locale (const char *input, char **output)
916 return idna_to_unicode_locale_from_locale (input, output, 0, 0);