LCOV - code coverage report
Current view: top level - lib - strerror-stringprep.c (source / functions) Hit Total Coverage
Test: GNU Libidn Lines: 40 46 87.0 %
Date: 2020-07-22 17:53:13 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* strerror-stringprep.c --- Convert stringprep errors into text.
       2             :    Copyright (C) 2004-2020 Simon Josefsson
       3             : 
       4             :    This file is part of GNU Libidn.
       5             : 
       6             :    GNU Libidn is free software: you can redistribute it and/or
       7             :    modify it under the terms of either:
       8             : 
       9             :      * the GNU Lesser General Public License as published by the Free
      10             :        Software Foundation; either version 3 of the License, or (at
      11             :        your option) any later version.
      12             : 
      13             :    or
      14             : 
      15             :      * the GNU General Public License as published by the Free
      16             :        Software Foundation; either version 2 of the License, or (at
      17             :        your option) any later version.
      18             : 
      19             :    or both in parallel, as here.
      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/>. */
      29             : 
      30             : #ifdef HAVE_CONFIG_H
      31             : # include "config.h"
      32             : #endif
      33             : 
      34             : #include "stringprep.h"
      35             : 
      36             : #include "gettext.h"
      37             : #define _(String) dgettext (PACKAGE, String)
      38             : 
      39             : /**
      40             :  * stringprep_strerror:
      41             :  * @rc: a #Stringprep_rc return code.
      42             :  *
      43             :  * Convert a return code integer to a text string.  This string can be
      44             :  * used to output a diagnostic message to the user.
      45             :  *
      46             :  * STRINGPREP_OK: Successful operation.  This value is guaranteed to
      47             :  *   always be zero, the remaining ones are only guaranteed to hold
      48             :  *   non-zero values, for logical comparison purposes.
      49             :  * STRINGPREP_CONTAINS_UNASSIGNED: String contain unassigned Unicode
      50             :  *   code points, which is forbidden by the profile.
      51             :  * STRINGPREP_CONTAINS_PROHIBITED: String contain code points
      52             :  *   prohibited by the profile.
      53             :  * STRINGPREP_BIDI_BOTH_L_AND_RAL: String contain code points with
      54             :  *   conflicting bidirection category.
      55             :  * STRINGPREP_BIDI_LEADTRAIL_NOT_RAL: Leading and trailing character
      56             :  *   in string not of proper bidirectional category.
      57             :  * STRINGPREP_BIDI_CONTAINS_PROHIBITED: Contains prohibited code
      58             :  *   points detected by bidirectional code.
      59             :  * STRINGPREP_TOO_SMALL_BUFFER: Buffer handed to function was too
      60             :  *   small.  This usually indicate a problem in the calling
      61             :  *   application.
      62             :  * STRINGPREP_PROFILE_ERROR: The stringprep profile was inconsistent.
      63             :  *   This usually indicate an internal error in the library.
      64             :  * STRINGPREP_FLAG_ERROR: The supplied flag conflicted with profile.
      65             :  *   This usually indicate a problem in the calling application.
      66             :  * STRINGPREP_UNKNOWN_PROFILE: The supplied profile name was not
      67             :  *   known to the library.
      68             :  * STRINGPREP_ICONV_ERROR: Character encoding conversion error.
      69             :  * STRINGPREP_NFKC_FAILED: The Unicode NFKC operation failed.  This
      70             :  *   usually indicate an internal error in the library.
      71             :  * STRINGPREP_MALLOC_ERROR: The malloc() was out of memory.  This is
      72             :  *   usually a fatal error.
      73             :  *
      74             :  * Return value: Returns a pointer to a statically allocated string
      75             :  *   containing a description of the error with the return code @rc.
      76             :  **/
      77             : const char *
      78          17 : stringprep_strerror (Stringprep_rc rc)
      79             : {
      80             :   const char *p;
      81             : 
      82          17 :   bindtextdomain (PACKAGE, LOCALEDIR);
      83             : 
      84          17 :   switch (rc)
      85             :     {
      86           2 :     case STRINGPREP_OK:
      87           2 :       p = _("Success");
      88           2 :       break;
      89             : 
      90           1 :     case STRINGPREP_CONTAINS_UNASSIGNED:
      91           1 :       p = _("Forbidden unassigned code points in input");
      92           1 :       break;
      93             : 
      94           1 :     case STRINGPREP_CONTAINS_PROHIBITED:
      95           1 :       p = _("Prohibited code points in input");
      96           1 :       break;
      97             : 
      98           1 :     case STRINGPREP_BIDI_BOTH_L_AND_RAL:
      99           1 :       p = _("Conflicting bidirectional properties in input");
     100           1 :       break;
     101             : 
     102           1 :     case STRINGPREP_BIDI_LEADTRAIL_NOT_RAL:
     103           1 :       p = _("Malformed bidirectional string");
     104           1 :       break;
     105             : 
     106           1 :     case STRINGPREP_BIDI_CONTAINS_PROHIBITED:
     107           1 :       p = _("Prohibited bidirectional code points in input");
     108           1 :       break;
     109             : 
     110           1 :     case STRINGPREP_TOO_SMALL_BUFFER:
     111           1 :       p = _("Output would exceed the buffer space provided");
     112           1 :       break;
     113             : 
     114           1 :     case STRINGPREP_PROFILE_ERROR:
     115           1 :       p = _("Error in stringprep profile definition");
     116           1 :       break;
     117             : 
     118           1 :     case STRINGPREP_FLAG_ERROR:
     119           1 :       p = _("Flag conflict with profile");
     120           1 :       break;
     121             : 
     122           1 :     case STRINGPREP_UNKNOWN_PROFILE:
     123           1 :       p = _("Unknown profile");
     124           1 :       break;
     125             : 
     126           1 :     case STRINGPREP_ICONV_ERROR:
     127           1 :       p = _("Character encoding conversion error");
     128           1 :       break;
     129             : 
     130           0 :     case STRINGPREP_NFKC_FAILED:
     131           0 :       p = _("Unicode normalization failed (internal error)");
     132           0 :       break;
     133             : 
     134           0 :     case STRINGPREP_MALLOC_ERROR:
     135           0 :       p = _("Cannot allocate memory");
     136           0 :       break;
     137             : 
     138           5 :     default:
     139           5 :       p = _("Unknown error");
     140           5 :       break;
     141             :     }
     142             : 
     143          17 :   return p;
     144             : }

Generated by: LCOV version 1.13