LCOV - code coverage report
Current view: top level - builds/libidn/libidn2/lib - error.c (source / functions) Hit Total Coverage
Test: Libidn2-2.3.7.3-61ee Code Coverage Lines: 122 122 100.0 %
Date: 2024-12-01 07:08:19 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* error.c - libidn2 error handling helpers.
       2             :    Copyright (C) 2011-2024 Simon Josefsson
       3             : 
       4             :    Libidn2 is free software: you can redistribute it and/or modify it
       5             :    under the terms of either:
       6             : 
       7             :      * the GNU Lesser General Public License as published by the Free
       8             :        Software Foundation; either version 3 of the License, or (at
       9             :        your option) any later version.
      10             : 
      11             :    or
      12             : 
      13             :      * the GNU General Public License as published by the Free
      14             :        Software Foundation; either version 2 of the License, or (at
      15             :        your option) any later version.
      16             : 
      17             :    or both in parallel, as here.
      18             : 
      19             :    This program is distributed in the hope that it will be useful,
      20             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      21             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      22             :    GNU General Public License for more details.
      23             : 
      24             :    You should have received copies of the GNU General Public License and
      25             :    the GNU Lesser General Public License along with this program.  If
      26             :    not, see <http://www.gnu.org/licenses/>.
      27             : */
      28             : 
      29             : #include <config.h>
      30             : 
      31             : #include "idn2.h"
      32             : 
      33             : /* Prepare for gettext. */
      34             : #define _(x) x
      35             : #define bindtextdomain(a,b)
      36             : 
      37             : /**
      38             :  * idn2_strerror:
      39             :  * @rc: return code from another libidn2 function.
      40             :  *
      41             :  * Convert internal libidn2 error code to a humanly readable string.
      42             :  * The returned pointer must not be de-allocated by the caller.
      43             :  *
      44             :  * Return value: A humanly readable string describing error.
      45             :  **/
      46             : const char *
      47        2035 : idn2_strerror (int rc)
      48             : {
      49             :   bindtextdomain (PACKAGE, LOCALEDIR);
      50             : 
      51        2035 :   switch (rc)
      52             :     {
      53           1 :     case IDN2_OK:
      54           1 :       return _("success");
      55           1 :     case IDN2_MALLOC:
      56           1 :       return _("out of memory");
      57           1 :     case IDN2_NO_CODESET:
      58           1 :       return _("could not determine locale encoding format");
      59           1 :     case IDN2_ICONV_FAIL:
      60           1 :       return _("could not convert string to UTF-8");
      61           5 :     case IDN2_ENCODING_ERROR:
      62           5 :       return _("string encoding error");
      63           1 :     case IDN2_NFC:
      64           1 :       return _("string could not be NFC normalized");
      65          31 :     case IDN2_PUNYCODE_BAD_INPUT:
      66          31 :       return _("string contains invalid punycode data");
      67           1 :     case IDN2_PUNYCODE_BIG_OUTPUT:
      68           1 :       return _("punycode encoded data will be too large");
      69           1 :     case IDN2_PUNYCODE_OVERFLOW:
      70           1 :       return _("punycode conversion resulted in overflow");
      71           1 :     case IDN2_TOO_BIG_DOMAIN:
      72           1 :       return _("domain name longer than 255 characters");
      73           1 :     case IDN2_TOO_BIG_LABEL:
      74           1 :       return _("domain label longer than 63 characters");
      75           1 :     case IDN2_INVALID_ALABEL:
      76           1 :       return _("input A-label is not valid");
      77           1 :     case IDN2_UALABEL_MISMATCH:
      78           1 :       return _("input A-label and U-label does not match");
      79           1 :     case IDN2_NOT_NFC:
      80           1 :       return _("string is not in Unicode NFC format");
      81           1 :     case IDN2_2HYPHEN:
      82           1 :       return _("string contains forbidden two hyphens pattern");
      83           1 :     case IDN2_HYPHEN_STARTEND:
      84           1 :       return _("string start/ends with forbidden hyphen");
      85           1 :     case IDN2_LEADING_COMBINING:
      86           1 :       return _("string contains a forbidden leading combining character");
      87           1 :     case IDN2_DISALLOWED:
      88           1 :       return _("string contains a disallowed character");
      89           1 :     case IDN2_CONTEXTJ:
      90           1 :       return _("string contains a forbidden context-j character");
      91           1 :     case IDN2_CONTEXTJ_NO_RULE:
      92           1 :       return _("string contains a context-j character with null rule");
      93           1 :     case IDN2_CONTEXTO:
      94           1 :       return _("string contains a forbidden context-o character");
      95           1 :     case IDN2_CONTEXTO_NO_RULE:
      96           1 :       return _("string contains a context-o character with null rule");
      97           1 :     case IDN2_UNASSIGNED:
      98           1 :       return _("string contains unassigned code point");
      99           1 :     case IDN2_BIDI:
     100           1 :       return _("string has forbidden bi-directional properties");
     101           1 :     case IDN2_DOT_IN_LABEL:
     102           1 :       return _("domain label has forbidden dot (TR46)");
     103           1 :     case IDN2_INVALID_TRANSITIONAL:
     104             :       return
     105           1 :         _("domain label has character forbidden in transitional mode (TR46)");
     106           1 :     case IDN2_INVALID_NONTRANSITIONAL:
     107             :       return
     108           1 :         _
     109             :         ("domain label has character forbidden in non-transitional mode (TR46)");
     110           1 :     case IDN2_ALABEL_ROUNDTRIP_FAILED:
     111           1 :       return _("A-label roundtrip failed");
     112        1973 :     default:
     113        1973 :       return _("Unknown error");
     114             :     }
     115             : }
     116             : 
     117             : #define ERR2STR(name) #name
     118             : 
     119             : /**
     120             :  * idn2_strerror_name:
     121             :  * @rc: return code from another libidn2 function.
     122             :  *
     123             :  * Convert internal libidn2 error code to a string corresponding to
     124             :  * internal header file symbols.  For example,
     125             :  * idn2_strerror_name(IDN2_MALLOC) will return the string
     126             :  * "IDN2_MALLOC".
     127             :  *
     128             :  * The caller must not attempt to de-allocate the returned string.
     129             :  *
     130             :  * Return value: A string corresponding to error code symbol.
     131             :  **/
     132             : const char *
     133        2862 : idn2_strerror_name (int rc)
     134             : {
     135        2862 :   switch (rc)
     136             :     {
     137         553 :     case IDN2_OK:
     138         553 :       return ERR2STR (IDN2_OK);
     139           1 :     case IDN2_MALLOC:
     140           1 :       return ERR2STR (IDN2_MALLOC);
     141           1 :     case IDN2_NO_CODESET:
     142           1 :       return ERR2STR (IDN2_NO_NODESET);
     143           1 :     case IDN2_ICONV_FAIL:
     144           1 :       return ERR2STR (IDN2_ICONV_FAIL);
     145          10 :     case IDN2_ENCODING_ERROR:
     146          10 :       return ERR2STR (IDN2_ENCODING_ERROR);
     147           1 :     case IDN2_NFC:
     148           1 :       return ERR2STR (IDN2_NFC);
     149           1 :     case IDN2_PUNYCODE_BAD_INPUT:
     150           1 :       return ERR2STR (IDN2_PUNYCODE_BAD_INPUT);
     151           1 :     case IDN2_PUNYCODE_BIG_OUTPUT:
     152           1 :       return ERR2STR (IDN2_PUNYCODE_BIG_OUTPUT);
     153           1 :     case IDN2_PUNYCODE_OVERFLOW:
     154           1 :       return ERR2STR (IDN2_PUNYCODE_OVERFLOW);
     155           1 :     case IDN2_TOO_BIG_DOMAIN:
     156           1 :       return ERR2STR (IDN2_TOO_BIG_DOMAIN);
     157           2 :     case IDN2_TOO_BIG_LABEL:
     158           2 :       return ERR2STR (IDN2_TOO_BIG_LABEL);
     159           2 :     case IDN2_INVALID_ALABEL:
     160           2 :       return ERR2STR (IDN2_INVALID_ALABEL);
     161           1 :     case IDN2_UALABEL_MISMATCH:
     162           1 :       return ERR2STR (IDN2_UALABEL_MISMATCH);
     163           5 :     case IDN2_INVALID_FLAGS:
     164           5 :       return ERR2STR (IDN2_INVALID_FLAGS);
     165          25 :     case IDN2_NOT_NFC:
     166          25 :       return ERR2STR (IDN2_NOT_NFC);
     167           5 :     case IDN2_2HYPHEN:
     168           5 :       return ERR2STR (IDN2_2HYPHEN);
     169           1 :     case IDN2_HYPHEN_STARTEND:
     170           1 :       return ERR2STR (IDN2_HYPHEN_STARTEND);
     171          21 :     case IDN2_LEADING_COMBINING:
     172          21 :       return ERR2STR (IDN2_LEADING_COMBINING);
     173         170 :     case IDN2_DISALLOWED:
     174         170 :       return ERR2STR (IDN2_DISALLOWED);
     175          19 :     case IDN2_CONTEXTJ:
     176          19 :       return ERR2STR (IDN2_CONTEXTJ);
     177           1 :     case IDN2_CONTEXTJ_NO_RULE:
     178           1 :       return ERR2STR (IDN2_CONTEXTJ_NO_RULE);
     179          23 :     case IDN2_CONTEXTO:
     180          23 :       return ERR2STR (IDN2_CONTEXTO);
     181           1 :     case IDN2_CONTEXTO_NO_RULE:
     182           1 :       return ERR2STR (IDN2_CONTEXTO_NO_RULE);
     183           7 :     case IDN2_UNASSIGNED:
     184           7 :       return ERR2STR (IDN2_UNASSIGNED);
     185          26 :     case IDN2_BIDI:
     186          26 :       return ERR2STR (IDN2_BIDI);
     187           1 :     case IDN2_DOT_IN_LABEL:
     188           1 :       return ERR2STR (IDN2_DOT_IN_LABEL);
     189           1 :     case IDN2_INVALID_TRANSITIONAL:
     190           1 :       return ERR2STR (IDN2_INVALID_TRANSITIONAL);
     191           1 :     case IDN2_INVALID_NONTRANSITIONAL:
     192           1 :       return ERR2STR (IDN2_INVALID_NONTRANSITIONAL);
     193           7 :     case IDN2_ALABEL_ROUNDTRIP_FAILED:
     194           7 :       return ERR2STR (IDN2_ALABEL_ROUNDTRIP_FAILED);
     195        1972 :     default:
     196        1972 :       return "IDN2_UNKNOWN";
     197             :     }
     198             : }

Generated by: LCOV version 1.16