1 /* assuan-errors.c - error codes
2  *	Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
3  *	Copyright (C) 2005 Free Software Foundation, Inc.
4  *
5  * This file is part of Assuan.
6  *
7  * Assuan is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * Assuan is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 /* Please note that this is a stripped down and modified version of
22    the orginal Assuan code from libassuan. */
23 
24 #include <stdio.h>
25 #include "assuan.h"
26 
27 /* This function returns a textual representaion of the given error
28    code.  If this is an unknown value, a string with the value is
29    returned (Beware: it is hold in a static buffer).  Return value:
30    String with the error description.
31  */
32 const char *
assuan_strerror(assuan_error_t err)33 assuan_strerror (assuan_error_t err)
34 {
35   const char *s;
36   static char buf[50];
37 
38   switch (err)
39     {
40     case ASSUAN_No_Error: s="no error"; break;
41     case ASSUAN_General_Error: s="general error"; break;
42     case ASSUAN_Out_Of_Core: s="out of core"; break;
43     case ASSUAN_Invalid_Value: s="invalid value"; break;
44     case ASSUAN_Timeout: s="timeout"; break;
45     case ASSUAN_Read_Error: s="read error"; break;
46     case ASSUAN_Write_Error: s="write error"; break;
47     case ASSUAN_Problem_Starting_Server: s="problem starting server"; break;
48     case ASSUAN_Not_A_Server: s="not a server"; break;
49     case ASSUAN_Not_A_Client: s="not a client"; break;
50     case ASSUAN_Nested_Commands: s="nested commands"; break;
51     case ASSUAN_Invalid_Response: s="invalid response"; break;
52     case ASSUAN_No_Data_Callback: s="no data callback"; break;
53     case ASSUAN_No_Inquire_Callback: s="no inquire callback"; break;
54     case ASSUAN_Connect_Failed: s="connect failed"; break;
55     case ASSUAN_Accept_Failed: s="accept failed"; break;
56     case ASSUAN_Not_Implemented: s="not implemented"; break;
57     case ASSUAN_Server_Fault: s="server fault"; break;
58     case ASSUAN_Invalid_Command: s="invalid command"; break;
59     case ASSUAN_Unknown_Command: s="unknown command"; break;
60     case ASSUAN_Syntax_Error: s="syntax error"; break;
61     case ASSUAN_Parameter_Error: s="parameter error"; break;
62     case ASSUAN_Parameter_Conflict: s="parameter conflict"; break;
63     case ASSUAN_Line_Too_Long: s="line too long"; break;
64     case ASSUAN_Line_Not_Terminated: s="line not terminated"; break;
65     case ASSUAN_No_Input: s="no input"; break;
66     case ASSUAN_No_Output: s="no output"; break;
67     case ASSUAN_Canceled: s="canceled"; break;
68     case ASSUAN_Unsupported_Algorithm: s="unsupported algorithm"; break;
69     case ASSUAN_Server_Resource_Problem: s="server resource problem"; break;
70     case ASSUAN_Server_IO_Error: s="server io error"; break;
71     case ASSUAN_Server_Bug: s="server bug"; break;
72     case ASSUAN_No_Data_Available: s="no data available"; break;
73     case ASSUAN_Invalid_Data: s="invalid data"; break;
74     case ASSUAN_Unexpected_Command: s="unexpected command"; break;
75     case ASSUAN_Too_Much_Data: s="too much data"; break;
76     case ASSUAN_Inquire_Unknown: s="inquire unknown"; break;
77     case ASSUAN_Inquire_Error: s="inquire error"; break;
78     case ASSUAN_Invalid_Option: s="invalid option"; break;
79     case ASSUAN_Invalid_Index: s="invalid index"; break;
80     case ASSUAN_Unexpected_Status: s="unexpected status"; break;
81     case ASSUAN_Unexpected_Data: s="unexpected data"; break;
82     case ASSUAN_Invalid_Status: s="invalid status"; break;
83     case ASSUAN_Locale_Problem: s="locale problem"; break;
84     case ASSUAN_Not_Confirmed: s="not confirmed"; break;
85     case ASSUAN_USER_ERROR_FIRST: s="user error first"; break;
86     case ASSUAN_USER_ERROR_LAST: s="user error last"; break;
87     default:
88       {
89         unsigned int source, code;
90 
91         source = ((err >> 24) & 0xff);
92         code = (err & 0x00ffffff);
93         if (source) /* Assume this is an libgpg-error. */
94           sprintf (buf, "ec=%u.%u", source, code );
95         else
96           sprintf (buf, "ec=%d", err );
97         s=buf; break;
98       }
99     }
100 
101   return s;
102 }
103 
104