File: assuan-errors.c

package info (click to toggle)
gnupg 1.4.18-7+deb8u5
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 34,476 kB
  • sloc: ansic: 127,074; sh: 7,535; asm: 4,610; makefile: 1,186; yacc: 291; perl: 196; pascal: 72; sed: 16
file content (103 lines) | stat: -rw-r--r-- 4,490 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* assuan-errors.c - error codes
 *	Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
 *	Copyright (C) 2005 Free Software Foundation, Inc.
 *
 * This file is part of Assuan.
 *
 * Assuan is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * Assuan is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

/* Please note that this is a stripped down and modified version of
   the orginal Assuan code from libassuan. */ 

#include <stdio.h>
#include "assuan.h"

/* This function returns a textual representaion of the given error
   code.  If this is an unknown value, a string with the value is
   returned (Beware: it is hold in a static buffer).  Return value:
   String with the error description.
 */
const char *
assuan_strerror (assuan_error_t err)
{
  const char *s;
  static char buf[50];

  switch (err)
    {
    case ASSUAN_No_Error: s="no error"; break;
    case ASSUAN_General_Error: s="general error"; break;
    case ASSUAN_Out_Of_Core: s="out of core"; break;
    case ASSUAN_Invalid_Value: s="invalid value"; break;
    case ASSUAN_Timeout: s="timeout"; break;
    case ASSUAN_Read_Error: s="read error"; break;
    case ASSUAN_Write_Error: s="write error"; break;
    case ASSUAN_Problem_Starting_Server: s="problem starting server"; break;
    case ASSUAN_Not_A_Server: s="not a server"; break;
    case ASSUAN_Not_A_Client: s="not a client"; break;
    case ASSUAN_Nested_Commands: s="nested commands"; break;
    case ASSUAN_Invalid_Response: s="invalid response"; break;
    case ASSUAN_No_Data_Callback: s="no data callback"; break;
    case ASSUAN_No_Inquire_Callback: s="no inquire callback"; break;
    case ASSUAN_Connect_Failed: s="connect failed"; break;
    case ASSUAN_Accept_Failed: s="accept failed"; break;
    case ASSUAN_Not_Implemented: s="not implemented"; break;
    case ASSUAN_Server_Fault: s="server fault"; break;
    case ASSUAN_Invalid_Command: s="invalid command"; break;
    case ASSUAN_Unknown_Command: s="unknown command"; break;
    case ASSUAN_Syntax_Error: s="syntax error"; break;
    case ASSUAN_Parameter_Error: s="parameter error"; break;
    case ASSUAN_Parameter_Conflict: s="parameter conflict"; break;
    case ASSUAN_Line_Too_Long: s="line too long"; break;
    case ASSUAN_Line_Not_Terminated: s="line not terminated"; break;
    case ASSUAN_No_Input: s="no input"; break;
    case ASSUAN_No_Output: s="no output"; break;
    case ASSUAN_Canceled: s="canceled"; break;
    case ASSUAN_Unsupported_Algorithm: s="unsupported algorithm"; break;
    case ASSUAN_Server_Resource_Problem: s="server resource problem"; break;
    case ASSUAN_Server_IO_Error: s="server io error"; break;
    case ASSUAN_Server_Bug: s="server bug"; break;
    case ASSUAN_No_Data_Available: s="no data available"; break;
    case ASSUAN_Invalid_Data: s="invalid data"; break;
    case ASSUAN_Unexpected_Command: s="unexpected command"; break;
    case ASSUAN_Too_Much_Data: s="too much data"; break;
    case ASSUAN_Inquire_Unknown: s="inquire unknown"; break;
    case ASSUAN_Inquire_Error: s="inquire error"; break;
    case ASSUAN_Invalid_Option: s="invalid option"; break;
    case ASSUAN_Invalid_Index: s="invalid index"; break;
    case ASSUAN_Unexpected_Status: s="unexpected status"; break;
    case ASSUAN_Unexpected_Data: s="unexpected data"; break;
    case ASSUAN_Invalid_Status: s="invalid status"; break;
    case ASSUAN_Locale_Problem: s="locale problem"; break;
    case ASSUAN_Not_Confirmed: s="not confirmed"; break;
    case ASSUAN_USER_ERROR_FIRST: s="user error first"; break;
    case ASSUAN_USER_ERROR_LAST: s="user error last"; break;
    default: 
      {
        unsigned int source, code;

        source = ((err >> 24) & 0xff);
        code = (err & 0x00ffffff);
        if (source) /* Assume this is an libgpg-error. */
          sprintf (buf, "ec=%u.%u", source, code ); 
        else
          sprintf (buf, "ec=%d", err ); 
        s=buf; break;
      }
    }

  return s;
}