summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '3rdParty/LibIDN/src/stringprep.c')
-rw-r--r--3rdParty/LibIDN/src/stringprep.c73
1 files changed, 45 insertions, 28 deletions
diff --git a/3rdParty/LibIDN/src/stringprep.c b/3rdParty/LibIDN/src/stringprep.c
index 96fa316..8ff28e6 100644
--- a/3rdParty/LibIDN/src/stringprep.c
+++ b/3rdParty/LibIDN/src/stringprep.c
@@ -1,25 +1,33 @@
1/* stringprep.c --- Core stringprep implementation. 1/* stringprep.c --- Core stringprep implementation.
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
@@ -102,11 +110,11 @@ stringprep_apply_table_to_string (uint32_t * ucs4,
102#define UNAPPLICAPLEFLAGS(flags, profileflags) \ 110#define UNAPPLICAPLEFLAGS(flags, profileflags) \
103 ((!INVERTED(profileflags) && !(profileflags & flags) && profileflags) || \ 111 ((!INVERTED(profileflags) && !(profileflags & flags) && profileflags) || \
104 ( INVERTED(profileflags) && (profileflags & flags))) 112 ( INVERTED(profileflags) && (profileflags & flags)))
105 113
106/** 114/**
107 * stringprep_4i - prepare internationalized string 115 * stringprep_4i:
108 * @ucs4: input/output array with string to prepare. 116 * @ucs4: input/output array with string to prepare.
109 * @len: on input, length of input array with Unicode code points, 117 * @len: on input, length of input array with Unicode code points,
110 * on exit, length of output array with Unicode code points. 118 * on exit, length of output array with Unicode code points.
111 * @maxucs4len: maximum length of input/output array. 119 * @maxucs4len: maximum length of input/output array.
112 * @flags: a #Stringprep_profile_flags value, or 0. 120 * @flags: a #Stringprep_profile_flags value, or 0.
@@ -290,11 +298,11 @@ stringprep_4zi_1 (uint32_t * ucs4, size_t ucs4len, size_t maxucs4len,
290 298
291 return STRINGPREP_OK; 299 return STRINGPREP_OK;
292} 300}
293 301
294/** 302/**
295 * stringprep_4zi - prepare internationalized string 303 * stringprep_4zi:
296 * @ucs4: input/output array with zero terminated string to prepare. 304 * @ucs4: input/output array with zero terminated string to prepare.
297 * @maxucs4len: maximum length of input/output array. 305 * @maxucs4len: maximum length of input/output array.
298 * @flags: a #Stringprep_profile_flags value, or 0. 306 * @flags: a #Stringprep_profile_flags value, or 0.
299 * @profile: pointer to #Stringprep_profile to use. 307 * @profile: pointer to #Stringprep_profile to use.
300 * 308 *
@@ -327,11 +335,11 @@ stringprep_4zi (uint32_t * ucs4, size_t maxucs4len,
327 335
328 return stringprep_4zi_1 (ucs4, ucs4len, maxucs4len, flags, profile); 336 return stringprep_4zi_1 (ucs4, ucs4len, maxucs4len, flags, profile);
329} 337}
330 338
331/** 339/**
332 * stringprep - prepare internationalized string 340 * stringprep:
333 * @in: input/ouput array with string to prepare. 341 * @in: input/ouput array with string to prepare.
334 * @maxlen: maximum length of input/output array. 342 * @maxlen: maximum length of input/output array.
335 * @flags: a #Stringprep_profile_flags value, or 0. 343 * @flags: a #Stringprep_profile_flags value, or 0.
336 * @profile: pointer to #Stringprep_profile to use. 344 * @profile: pointer to #Stringprep_profile to use.
337 * 345 *
@@ -368,13 +376,14 @@ stringprep (char *in,
368 376
369 do 377 do
370 { 378 {
371 uint32_t *newp; 379 uint32_t *newp;
372 380
373 if (ucs4) 381 free (ucs4);
374 free (ucs4);
375 ucs4 = stringprep_utf8_to_ucs4 (in, -1, &ucs4len); 382 ucs4 = stringprep_utf8_to_ucs4 (in, -1, &ucs4len);
383 if (ucs4 == NULL)
384 return STRINGPREP_ICONV_ERROR;
376 maxucs4len = ucs4len + adducs4len; 385 maxucs4len = ucs4len + adducs4len;
377 newp = realloc (ucs4, maxucs4len * sizeof (uint32_t)); 386 newp = realloc (ucs4, maxucs4len * sizeof (uint32_t));
378 if (!newp) 387 if (!newp)
379 { 388 {
380 free (ucs4); 389 free (ucs4);
@@ -393,11 +402,11 @@ stringprep (char *in,
393 } 402 }
394 403
395 utf8 = stringprep_ucs4_to_utf8 (ucs4, ucs4len, 0, 0); 404 utf8 = stringprep_ucs4_to_utf8 (ucs4, ucs4len, 0, 0);
396 free (ucs4); 405 free (ucs4);
397 if (!utf8) 406 if (!utf8)
398 return STRINGPREP_MALLOC_ERROR; 407 return STRINGPREP_ICONV_ERROR;
399 408
400 if (strlen (utf8) >= maxlen) 409 if (strlen (utf8) >= maxlen)
401 { 410 {
402 free (utf8); 411 free (utf8);
403 return STRINGPREP_TOO_SMALL_BUFFER; 412 return STRINGPREP_TOO_SMALL_BUFFER;
@@ -409,11 +418,11 @@ stringprep (char *in,
409 418
410 return STRINGPREP_OK; 419 return STRINGPREP_OK;
411} 420}
412 421
413/** 422/**
414 * stringprep_profile - prepare internationalized string 423 * stringprep_profile:
415 * @in: input array with UTF-8 string to prepare. 424 * @in: input array with UTF-8 string to prepare.
416 * @out: output variable with pointer to newly allocate string. 425 * @out: output variable with pointer to newly allocate string.
417 * @profile: name of stringprep profile to use. 426 * @profile: name of stringprep profile to use.
418 * @flags: a #Stringprep_profile_flags value, or 0. 427 * @flags: a #Stringprep_profile_flags value, or 0.
419 * 428 *
@@ -451,12 +460,11 @@ stringprep_profile (const char *in,
451 if (!p || !p->name || !p->tables) 460 if (!p || !p->name || !p->tables)
452 return STRINGPREP_UNKNOWN_PROFILE; 461 return STRINGPREP_UNKNOWN_PROFILE;
453 462
454 do 463 do
455 { 464 {
456 if (str) 465 free (str);
457 free (str);
458 str = (char *) malloc (len); 466 str = (char *) malloc (len);
459 if (str == NULL) 467 if (str == NULL)
460 return STRINGPREP_MALLOC_ERROR; 468 return STRINGPREP_MALLOC_ERROR;
461 469
462 strcpy (str, in); 470 strcpy (str, in);
@@ -582,10 +590,11 @@ stringprep_profile (const char *in,
582 * This usually indicate an internal error in the library. 590 * This usually indicate an internal error in the library.
583 * @STRINGPREP_FLAG_ERROR: The supplied flag conflicted with profile. 591 * @STRINGPREP_FLAG_ERROR: The supplied flag conflicted with profile.
584 * This usually indicate a problem in the calling application. 592 * This usually indicate a problem in the calling application.
585 * @STRINGPREP_UNKNOWN_PROFILE: The supplied profile name was not 593 * @STRINGPREP_UNKNOWN_PROFILE: The supplied profile name was not
586 * known to the library. 594 * known to the library.
595 * @STRINGPREP_ICONV_ERROR: Could not convert string in locale encoding.
587 * @STRINGPREP_NFKC_FAILED: The Unicode NFKC operation failed. This 596 * @STRINGPREP_NFKC_FAILED: The Unicode NFKC operation failed. This
588 * usually indicate an internal error in the library. 597 * usually indicate an internal error in the library.
589 * @STRINGPREP_MALLOC_ERROR: The malloc() was out of memory. This is 598 * @STRINGPREP_MALLOC_ERROR: The malloc() was out of memory. This is
590 * usually a fatal error. 599 * usually a fatal error.
591 * 600 *
@@ -609,10 +618,18 @@ stringprep_profile (const char *in,
609 * Stringprep profile flags. 618 * Stringprep profile flags.
610 */ 619 */
611 620
612/** 621/**
613 * Stringprep_profile_steps: 622 * Stringprep_profile_steps:
623 * @STRINGPREP_NFKC: The NFKC step.
624 * @STRINGPREP_BIDI: The BIDI step.
625 * @STRINGPREP_MAP_TABLE: The MAP step.
626 * @STRINGPREP_UNASSIGNED_TABLE: The Unassigned step.
627 * @STRINGPREP_PROHIBIT_TABLE: The Prohibited step.
628 * @STRINGPREP_BIDI_PROHIBIT_TABLE: The BIDI-Prohibited step.
629 * @STRINGPREP_BIDI_RAL_TABLE: The BIDI-RAL step.
630 * @STRINGPREP_BIDI_L_TABLE: The BIDI-L step.
614 * 631 *
615 * Various steps in the stringprep algorithm. You really want to 632 * Various steps in the stringprep algorithm. You really want to
616 * study the source code to understand this one. Only useful if you 633 * study the source code to understand this one. Only useful if you
617 * want to add another profile. 634 * want to add another profile.
618 */ 635 */