summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-09-24 18:59:52 (GMT)
committerSwift Review <review@swift.im>2015-10-30 14:13:39 (GMT)
commit3d62970e1b929cf676202fc6cebc1cf426c14ff2 (patch)
treea68c82c3829a001c6f8cadbb2d68d91c98f617bf /3rdParty/LibIDN/src/idna.c
parent3cc7e86420e4b3d67c5882d8d68e1e6a003c6154 (diff)
downloadswift-3d62970e1b929cf676202fc6cebc1cf426c14ff2.zip
swift-3d62970e1b929cf676202fc6cebc1cf426c14ff2.tar.bz2
Update libIDN in 3rdParty to version 1.32
Updated existing libIDN files in 3rdParty folder to latest 1.32 version and added remaining dependencies for compilation. Updated SConscript file accordingly. Test-Information: Build and ran test=unit on OS X 10.10. Change-Id: Iec6506e1cc88fe2983b2019aca95a42580d1c80e
Diffstat (limited to '3rdParty/LibIDN/src/idna.c')
-rw-r--r--3rdParty/LibIDN/src/idna.c121
1 files changed, 74 insertions, 47 deletions
diff --git a/3rdParty/LibIDN/src/idna.c b/3rdParty/LibIDN/src/idna.c
index 8061086..5107d73 100644
--- a/3rdParty/LibIDN/src/idna.c
+++ b/3rdParty/LibIDN/src/idna.c
@@ -1,25 +1,33 @@
1/* idna.c --- Convert to or from IDN strings. 1/* idna.c --- Prototypes for Internationalized Domain Name library.
2 * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Simon Josefsson 2 Copyright (C) 2002-2015 Simon Josefsson
3 * 3
4 * This file is part of GNU Libidn. 4 This file is part of GNU Libidn.
5 * 5
6 * GNU Libidn is free software; you can redistribute it and/or 6 GNU Libidn is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public 7 modify it under the terms of either:
8 * License as published by the Free Software Foundation; either 8
9 * version 2.1 of the License, or (at your option) any later version. 9 * the GNU Lesser General Public License as published by the Free
10 * 10 Software Foundation; either version 3 of the License, or (at
11 * GNU Libidn is distributed in the hope that it will be useful, 11 your option) any later version.
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 or
14 * Lesser General Public License for more details. 14
15 * 15 * the GNU General Public License as published by the Free
16 * You should have received a copy of the GNU Lesser General Public 16 Software Foundation; either version 2 of the License, or (at
17 * License along with GNU Libidn; if not, write to the Free Software 17 your option) any later version.
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 18
19 * 19 or both in parallel, as here.
20 */ 20
21 GNU Libidn is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
25
26 You should have received copies of the GNU General Public License and
27 the GNU Lesser General Public License along with this program. If
28 not, see <http://www.gnu.org/licenses/>. */
21 29
22#ifdef HAVE_CONFIG_H 30#ifdef HAVE_CONFIG_H
23# include "config.h" 31# include "config.h"
24#endif 32#endif
25 33
@@ -28,17 +36,20 @@
28#include <stringprep.h> 36#include <stringprep.h>
29#include <punycode.h> 37#include <punycode.h>
30 38
31#include "idna.h" 39#include "idna.h"
32 40
41/* Get c_strcasecmp. */
42#include <c-strcase.h>
43
33#define DOTP(c) ((c) == 0x002E || (c) == 0x3002 || \ 44#define DOTP(c) ((c) == 0x002E || (c) == 0x3002 || \
34 (c) == 0xFF0E || (c) == 0xFF61) 45 (c) == 0xFF0E || (c) == 0xFF61)
35 46
36/* Core functions */ 47/* Core functions */
37 48
38/** 49/**
39 * idna_to_ascii_4i - convert Unicode domain name label to text 50 * idna_to_ascii_4i:
40 * @in: input array with unicode code points. 51 * @in: input array with unicode code points.
41 * @inlen: length of input array with unicode code points. 52 * @inlen: length of input array with unicode code points.
42 * @out: output zero terminated string that must have room for at 53 * @out: output zero terminated string that must have room for at
43 * least 63 characters plus the terminating zero. 54 * least 63 characters plus the terminating zero.
44 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or 55 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
@@ -107,11 +118,11 @@ idna_to_ascii_4i (const uint32_t * in, size_t inlen, char *out, int flags)
107 */ 118 */
108 119
109 { 120 {
110 char *p; 121 char *p;
111 122
112 p = stringprep_ucs4_to_utf8 (in, inlen, NULL, NULL); 123 p = stringprep_ucs4_to_utf8 (in, (ssize_t) inlen, NULL, NULL);
113 if (p == NULL) 124 if (p == NULL)
114 return IDNA_MALLOC_ERROR; 125 return IDNA_MALLOC_ERROR;
115 126
116 len = strlen (p); 127 len = strlen (p);
117 do 128 do
@@ -141,10 +152,13 @@ idna_to_ascii_4i (const uint32_t * in, size_t inlen, char *out, int flags)
141 } 152 }
142 153
143 src = stringprep_utf8_to_ucs4 (p, -1, NULL); 154 src = stringprep_utf8_to_ucs4 (p, -1, NULL);
144 155
145 free (p); 156 free (p);
157
158 if (!src)
159 return IDNA_MALLOC_ERROR;
146 } 160 }
147 161
148step3: 162step3:
149 /* 163 /*
150 * 3. If the UseSTD3ASCIIRules flag is set, then perform these checks: 164 * 3. If the UseSTD3ASCIIRules flag is set, then perform these checks:
@@ -316,14 +330,16 @@ idna_to_unicode_internal (char *utf8in,
316 return IDNA_STRINGPREP_ERROR; 330 return IDNA_STRINGPREP_ERROR;
317 } 331 }
318 332
319 /* 3. Verify that the sequence begins with the ACE prefix, and save a 333 /* 3. Verify that the sequence begins with the ACE prefix, and save a
320 * copy of the sequence. 334 * copy of the sequence.
335 * ... The ToASCII and ToUnicode operations MUST recognize the ACE
336 prefix in a case-insensitive manner.
321 */ 337 */
322 338
323step3: 339step3:
324 if (memcmp (IDNA_ACE_PREFIX, utf8in, strlen (IDNA_ACE_PREFIX)) != 0) 340 if (c_strncasecmp (utf8in, IDNA_ACE_PREFIX, strlen (IDNA_ACE_PREFIX)) != 0)
325 { 341 {
326 free (utf8in); 342 free (utf8in);
327 return IDNA_NO_ACE_PREFIX; 343 return IDNA_NO_ACE_PREFIX;
328 } 344 }
329 345
@@ -361,11 +377,11 @@ step3:
361 377
362 /* 7. Verify that the result of step 6 matches the saved copy from 378 /* 7. Verify that the result of step 6 matches the saved copy from
363 * step 3, using a case-insensitive ASCII comparison. 379 * step 3, using a case-insensitive ASCII comparison.
364 */ 380 */
365 381
366 if (strcasecmp (utf8in, tmpout + strlen (IDNA_ACE_PREFIX)) != 0) 382 if (c_strcasecmp (utf8in, tmpout + strlen (IDNA_ACE_PREFIX)) != 0)
367 { 383 {
368 free (utf8in); 384 free (utf8in);
369 return IDNA_ROUNDTRIP_VERIFY_ERROR; 385 return IDNA_ROUNDTRIP_VERIFY_ERROR;
370 } 386 }
371 387
@@ -375,11 +391,11 @@ step3:
375 free (utf8in); 391 free (utf8in);
376 return IDNA_SUCCESS; 392 return IDNA_SUCCESS;
377} 393}
378 394
379/** 395/**
380 * idna_to_unicode_44i - convert domain name label to Unicode 396 * idna_to_unicode_44i:
381 * @in: input array with unicode code points. 397 * @in: input array with unicode code points.
382 * @inlen: length of input array with unicode code points. 398 * @inlen: length of input array with unicode code points.
383 * @out: output array with unicode code points. 399 * @out: output array with unicode code points.
384 * @outlen: on input, maximum size of output array with unicode code points, 400 * @outlen: on input, maximum size of output array with unicode code points,
385 * on exit, actual size of output array with unicode code points. 401 * on exit, actual size of output array with unicode code points.
@@ -417,11 +433,11 @@ idna_to_unicode_44i (const uint32_t * in, size_t inlen,
417{ 433{
418 int rc; 434 int rc;
419 size_t outlensave = *outlen; 435 size_t outlensave = *outlen;
420 char *p; 436 char *p;
421 437
422 p = stringprep_ucs4_to_utf8 (in, inlen, NULL, NULL); 438 p = stringprep_ucs4_to_utf8 (in, (ssize_t) inlen, NULL, NULL);
423 if (p == NULL) 439 if (p == NULL)
424 return IDNA_MALLOC_ERROR; 440 return IDNA_MALLOC_ERROR;
425 441
426 rc = idna_to_unicode_internal (p, out, outlen, flags); 442 rc = idna_to_unicode_internal (p, out, outlen, flags);
427 if (rc != IDNA_SUCCESS) 443 if (rc != IDNA_SUCCESS)
@@ -437,11 +453,11 @@ idna_to_unicode_44i (const uint32_t * in, size_t inlen,
437} 453}
438 454
439/* Wrappers that handle several labels */ 455/* Wrappers that handle several labels */
440 456
441/** 457/**
442 * idna_to_ascii_4z - convert Unicode domain name to text 458 * idna_to_ascii_4z:
443 * @input: zero terminated input Unicode string. 459 * @input: zero terminated input Unicode string.
444 * @output: pointer to newly allocated output string. 460 * @output: pointer to newly allocated output string.
445 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or 461 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
446 * %IDNA_USE_STD3_ASCII_RULES. 462 * %IDNA_USE_STD3_ASCII_RULES.
447 * 463 *
@@ -453,11 +469,11 @@ idna_to_unicode_44i (const uint32_t * in, size_t inlen,
453 **/ 469 **/
454int 470int
455idna_to_ascii_4z (const uint32_t * input, char **output, int flags) 471idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
456{ 472{
457 const uint32_t *start = input; 473 const uint32_t *start = input;
458 const uint32_t *end = input; 474 const uint32_t *end;
459 char buf[64]; 475 char buf[64];
460 char *out = NULL; 476 char *out = NULL;
461 int rc; 477 int rc;
462 478
463 /* 1) Whenever dots are used as label separators, the following 479 /* 1) Whenever dots are used as label separators, the following
@@ -498,18 +514,22 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
498 /* Handle explicit zero-length root label. */ 514 /* Handle explicit zero-length root label. */
499 buf[0] = '\0'; 515 buf[0] = '\0';
500 } 516 }
501 else 517 else
502 { 518 {
503 rc = idna_to_ascii_4i (start, end - start, buf, flags); 519 rc = idna_to_ascii_4i (start, (size_t) (end - start), buf, flags);
504 if (rc != IDNA_SUCCESS) 520 if (rc != IDNA_SUCCESS)
505 return rc; 521 {
522 free (out);
523 return rc;
524 }
506 } 525 }
507 526
508 if (out) 527 if (out)
509 { 528 {
510 char *newp = realloc (out, strlen (out) + 1 + strlen (buf) + 1); 529 size_t l = strlen (out) + 1 + strlen (buf) + 1;
530 char *newp = realloc (out, l);
511 if (!newp) 531 if (!newp)
512 { 532 {
513 free (out); 533 free (out);
514 return IDNA_MALLOC_ERROR; 534 return IDNA_MALLOC_ERROR;
515 } 535 }
@@ -517,14 +537,13 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
517 strcat (out, "."); 537 strcat (out, ".");
518 strcat (out, buf); 538 strcat (out, buf);
519 } 539 }
520 else 540 else
521 { 541 {
522 out = (char *) malloc (strlen (buf) + 1); 542 out = strdup (buf);
523 if (!out) 543 if (!out)
524 return IDNA_MALLOC_ERROR; 544 return IDNA_MALLOC_ERROR;
525 strcpy (out, buf);
526 } 545 }
527 546
528 start = end + 1; 547 start = end + 1;
529 } 548 }
530 while (*end); 549 while (*end);
@@ -533,11 +552,11 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
533 552
534 return IDNA_SUCCESS; 553 return IDNA_SUCCESS;
535} 554}
536 555
537/** 556/**
538 * idna_to_ascii_8z - convert Unicode domain name to text 557 * idna_to_ascii_8z:
539 * @input: zero terminated input UTF-8 string. 558 * @input: zero terminated input UTF-8 string.
540 * @output: pointer to newly allocated output string. 559 * @output: pointer to newly allocated output string.
541 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or 560 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
542 * %IDNA_USE_STD3_ASCII_RULES. 561 * %IDNA_USE_STD3_ASCII_RULES.
543 * 562 *
@@ -565,11 +584,11 @@ idna_to_ascii_8z (const char *input, char **output, int flags)
565 return rc; 584 return rc;
566 585
567} 586}
568 587
569/** 588/**
570 * idna_to_ascii_lz - convert Unicode domain name to text 589 * idna_to_ascii_lz:
571 * @input: zero terminated input string encoded in the current locale's 590 * @input: zero terminated input string encoded in the current locale's
572 * character set. 591 * character set.
573 * @output: pointer to newly allocated output string. 592 * @output: pointer to newly allocated output string.
574 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or 593 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
575 * %IDNA_USE_STD3_ASCII_RULES. 594 * %IDNA_USE_STD3_ASCII_RULES.
@@ -596,11 +615,11 @@ idna_to_ascii_lz (const char *input, char **output, int flags)
596 615
597 return rc; 616 return rc;
598} 617}
599 618
600/** 619/**
601 * idna_to_unicode_4z4z - convert domain name to Unicode 620 * idna_to_unicode_4z4z:
602 * @input: zero-terminated Unicode string. 621 * @input: zero-terminated Unicode string.
603 * @output: pointer to newly allocated output Unicode string. 622 * @output: pointer to newly allocated output Unicode string.
604 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or 623 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
605 * %IDNA_USE_STD3_ASCII_RULES. 624 * %IDNA_USE_STD3_ASCII_RULES.
606 * 625 *
@@ -613,33 +632,33 @@ idna_to_ascii_lz (const char *input, char **output, int flags)
613 **/ 632 **/
614int 633int
615idna_to_unicode_4z4z (const uint32_t * input, uint32_t ** output, int flags) 634idna_to_unicode_4z4z (const uint32_t * input, uint32_t ** output, int flags)
616{ 635{
617 const uint32_t *start = input; 636 const uint32_t *start = input;
618 const uint32_t *end = input; 637 const uint32_t *end;
619 uint32_t *buf; 638 uint32_t *buf;
620 size_t buflen; 639 size_t buflen;
621 uint32_t *out = NULL; 640 uint32_t *out = NULL;
622 size_t outlen = 0; 641 size_t outlen = 0;
623 int rc;
624 642
625 *output = NULL; 643 *output = NULL;
626 644
627 do 645 do
628 { 646 {
629 end = start; 647 end = start;
630 648
631 for (; *end && !DOTP (*end); end++) 649 for (; *end && !DOTP (*end); end++)
632 ; 650 ;
633 651
634 buflen = end - start; 652 buflen = (size_t) (end - start);
635 buf = malloc (sizeof (buf[0]) * (buflen + 1)); 653 buf = malloc (sizeof (buf[0]) * (buflen + 1));
636 if (!buf) 654 if (!buf)
637 return IDNA_MALLOC_ERROR; 655 return IDNA_MALLOC_ERROR;
638 656
639 rc = idna_to_unicode_44i (start, end - start, buf, &buflen, flags); 657 /* don't check return code as per specification! */
640 /* don't check rc as per specification! */ 658 idna_to_unicode_44i (start, (size_t) (end - start),
659 buf, &buflen, flags);
641 660
642 if (out) 661 if (out)
643 { 662 {
644 uint32_t *newp = realloc (out, 663 uint32_t *newp = realloc (out,
645 sizeof (out[0]) 664 sizeof (out[0])
@@ -672,11 +691,11 @@ idna_to_unicode_4z4z (const uint32_t * input, uint32_t ** output, int flags)
672 691
673 return IDNA_SUCCESS; 692 return IDNA_SUCCESS;
674} 693}
675 694
676/** 695/**
677 * idna_to_unicode_8z4z - convert domain name to Unicode 696 * idna_to_unicode_8z4z:
678 * @input: zero-terminated UTF-8 string. 697 * @input: zero-terminated UTF-8 string.
679 * @output: pointer to newly allocated output Unicode string. 698 * @output: pointer to newly allocated output Unicode string.
680 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or 699 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
681 * %IDNA_USE_STD3_ASCII_RULES. 700 * %IDNA_USE_STD3_ASCII_RULES.
682 * 701 *
@@ -703,11 +722,11 @@ idna_to_unicode_8z4z (const char *input, uint32_t ** output, int flags)
703 722
704 return rc; 723 return rc;
705} 724}
706 725
707/** 726/**
708 * idna_to_unicode_8z8z - convert domain name to Unicode 727 * idna_to_unicode_8z8z:
709 * @input: zero-terminated UTF-8 string. 728 * @input: zero-terminated UTF-8 string.
710 * @output: pointer to newly allocated output UTF-8 string. 729 * @output: pointer to newly allocated output UTF-8 string.
711 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or 730 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
712 * %IDNA_USE_STD3_ASCII_RULES. 731 * %IDNA_USE_STD3_ASCII_RULES.
713 * 732 *
@@ -723,21 +742,24 @@ idna_to_unicode_8z8z (const char *input, char **output, int flags)
723{ 742{
724 uint32_t *ucs4; 743 uint32_t *ucs4;
725 int rc; 744 int rc;
726 745
727 rc = idna_to_unicode_8z4z (input, &ucs4, flags); 746 rc = idna_to_unicode_8z4z (input, &ucs4, flags);
747 if (rc != IDNA_SUCCESS)
748 return rc;
749
728 *output = stringprep_ucs4_to_utf8 (ucs4, -1, NULL, NULL); 750 *output = stringprep_ucs4_to_utf8 (ucs4, -1, NULL, NULL);
729 free (ucs4); 751 free (ucs4);
730 752
731 if (!*output) 753 if (!*output)
732 return IDNA_ICONV_ERROR; 754 return IDNA_ICONV_ERROR;
733 755
734 return rc; 756 return IDNA_SUCCESS;
735} 757}
736 758
737/** 759/**
738 * idna_to_unicode_8zlz - convert domain name to Unicode 760 * idna_to_unicode_8zlz:
739 * @input: zero-terminated UTF-8 string. 761 * @input: zero-terminated UTF-8 string.
740 * @output: pointer to newly allocated output string encoded in the 762 * @output: pointer to newly allocated output string encoded in the
741 * current locale's character set. 763 * current locale's character set.
742 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or 764 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
743 * %IDNA_USE_STD3_ASCII_RULES. 765 * %IDNA_USE_STD3_ASCII_RULES.
@@ -754,21 +776,24 @@ idna_to_unicode_8zlz (const char *input, char **output, int flags)
754{ 776{
755 char *utf8; 777 char *utf8;
756 int rc; 778 int rc;
757 779
758 rc = idna_to_unicode_8z8z (input, &utf8, flags); 780 rc = idna_to_unicode_8z8z (input, &utf8, flags);
781 if (rc != IDNA_SUCCESS)
782 return rc;
783
759 *output = stringprep_utf8_to_locale (utf8); 784 *output = stringprep_utf8_to_locale (utf8);
760 free (utf8); 785 free (utf8);
761 786
762 if (!*output) 787 if (!*output)
763 return IDNA_ICONV_ERROR; 788 return IDNA_ICONV_ERROR;
764 789
765 return rc; 790 return IDNA_SUCCESS;
766} 791}
767 792
768/** 793/**
769 * idna_to_unicode_lzlz - convert domain name to Unicode 794 * idna_to_unicode_lzlz:
770 * @input: zero-terminated string encoded in the current locale's 795 * @input: zero-terminated string encoded in the current locale's
771 * character set. 796 * character set.
772 * @output: pointer to newly allocated output string encoded in the 797 * @output: pointer to newly allocated output string encoded in the
773 * current locale's character set. 798 * current locale's character set.
774 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or 799 * @flags: an #Idna_flags value, e.g., %IDNA_ALLOW_UNASSIGNED or
@@ -810,10 +835,12 @@ idna_to_unicode_lzlz (const char *input, char **output, int flags)
810 * non-zero values, for logical comparison purposes. 835 * non-zero values, for logical comparison purposes.
811 * @IDNA_STRINGPREP_ERROR: Error during string preparation. 836 * @IDNA_STRINGPREP_ERROR: Error during string preparation.
812 * @IDNA_PUNYCODE_ERROR: Error during punycode operation. 837 * @IDNA_PUNYCODE_ERROR: Error during punycode operation.
813 * @IDNA_CONTAINS_NON_LDH: For IDNA_USE_STD3_ASCII_RULES, indicate that 838 * @IDNA_CONTAINS_NON_LDH: For IDNA_USE_STD3_ASCII_RULES, indicate that
814 * the string contains non-LDH ASCII characters. 839 * the string contains non-LDH ASCII characters.
840 * @IDNA_CONTAINS_LDH: Same as @IDNA_CONTAINS_NON_LDH, for compatibility
841 * with typo in earlier versions.
815 * @IDNA_CONTAINS_MINUS: For IDNA_USE_STD3_ASCII_RULES, indicate that 842 * @IDNA_CONTAINS_MINUS: For IDNA_USE_STD3_ASCII_RULES, indicate that
816 * the string contains a leading or trailing hyphen-minus (U+002D). 843 * the string contains a leading or trailing hyphen-minus (U+002D).
817 * @IDNA_INVALID_LENGTH: The final output string is not within the 844 * @IDNA_INVALID_LENGTH: The final output string is not within the
818 * (inclusive) range 1 to 63 characters. 845 * (inclusive) range 1 to 63 characters.
819 * @IDNA_NO_ACE_PREFIX: The string does not contain the ACE prefix 846 * @IDNA_NO_ACE_PREFIX: The string does not contain the ACE prefix