summaryrefslogtreecommitdiffstats
path: root/libtdenetwork/libgpgme-copy/assuan/mkerrors
blob: 57485411acfc25437e9a6da488e957a035f5a0f7 (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/sh
# mkerrors - Extract error strings from assuan.h
#            and create C source for assuan_strerror
#	Copyright (C) 2001, 2002, 2006 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 

cat <<EOF
/* Generated automatically by mkerrors */
/* Do not edit!  See mkerrors for copyright notice. */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <assert.h>
#include <errno.h>

#undef _ASSUAN_IN_LIBASSUAN /* undef to get all error codes. */
#include "assuan.h"

/* If true the modern gpg-error style error codes are used in the
   API. */
static unsigned int err_source;

/* Enable gpg-error style error codes.  ERRSOURCE is one of gpg-error
   sources.  Note, that this function is not thread-safe and should be
   used right at startup. Switching back to the old style mode is not
   supported. */
void
assuan_set_assuan_err_source (int errsource)
{
  errsource &= 0xff;
  err_source = errsource? errsource : 31 /*GPG_ERR_SOURCE_ANY*/;
}


/* Helper to map old style Assuan error codes to gpg-error codes.
   This is used internally to keep an compatible ABI. */
assuan_error_t
_assuan_error (int oldcode)
{
  unsigned int n;

  if (!err_source)
    return (oldcode & 0x00ffffff); /* Make sure that the gpg-error
                                      source part is cleared. */

  switch (oldcode)
    {
    case ASSUAN_General_Error:           n = 257; break;
    case ASSUAN_Accept_Failed:           n = 258; break;
    case ASSUAN_Connect_Failed:          n = 259; break;
    case ASSUAN_Invalid_Response:        n = 260; break;
    case ASSUAN_Invalid_Value:           n = 261; break;
    case ASSUAN_Line_Not_Terminated:     n = 262; break;
    case ASSUAN_Line_Too_Long:           n = 263; break;
    case ASSUAN_Nested_Commands:         n = 264; break;
    case ASSUAN_No_Data_Callback:        n = 265; break;
    case ASSUAN_No_Inquire_Callback:     n = 266; break;
    case ASSUAN_Not_A_Server:            n = 267; break;
    case ASSUAN_Not_Implemented:         n =  69; break;
    case ASSUAN_Parameter_Conflict:      n = 280; break;
    case ASSUAN_Problem_Starting_Server: n = 269; break;
    case ASSUAN_Server_Fault:            n =  80; break;
    case ASSUAN_Syntax_Error:            n = 276; break;
    case ASSUAN_Too_Much_Data:           n = 273; break;
    case ASSUAN_Unexpected_Command:      n = 274; break;
    case ASSUAN_Unknown_Command:         n = 275; break;
    case ASSUAN_Canceled:                n = 277; break;
    case ASSUAN_No_Secret_Key:           n =  17; break;
    case ASSUAN_Not_Confirmed:           n = 114; break;

    case ASSUAN_Read_Error:
      switch (errno)
        {
        case 0: n = 16381; /*GPG_ERR_MISSING_ERRNO*/  break;
        default: n = 270;  /*GPG_ERR_ASS_READ_ERROR*/ break;
        }
      break;

    case ASSUAN_Write_Error:
      switch (errno)
        {
        case 0: n = 16381; /*GPG_ERR_MISSING_ERRNO*/  break;
        default: n = 271;  /*GPG_ERR_ASS_WRITE_ERROR*/ break;
        }
      break;
      
    case ASSUAN_Out_Of_Core:
      switch (errno)
        {
        case 0:  /* Should not happen but a user might have provided
                    an incomplete implemented malloc function.  Give
                    him a chance to correct this fault but make sure
                    an error is indeed returned. */
          n = 16381; /*GPG_ERR_MISSING_ERRNO*/
          break;
        case ENOMEM: n = (1 << 15) | 86; break;
        default:  
          n = 16382; /*GPG_ERR_UNKNOWN_ERRNO*/
          break;
        }
      break;

    case -1: n = 16383 /*GPG_ERR_EOF*/; break;

    default:
      n = 257; 
      break;
    }

  return ((err_source << 24) | (n & 0x00ffffff));

}


/**
 * assuan_strerror:
 * @err:  Error code 
 * 
 * This function returns a textual representaion of the given
 * errorcode. 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)
    {
EOF

awk '
/ASSUAN_No_Error/        { okay=1 }
!okay                    {next}
/^#define[ ]+ASSUAN_[A-Za-z_]*/ { print_code($2) }
/ASSUAN_USER_ERROR_LAST/ { exit 0 }


function print_code( s )
{
printf "    case %s: s=\"", s ;
gsub(/_/, " ", s );
printf "%s\"; break;\n", tolower(substr(s,8));
}
'

cat <<EOF
  case -1: s = "EOF (-1)"; break;
    default: 
      {
        unsigned int source, code, n;

        source = ((err >> 24) & 0xff);
        code = (err & 0x00ffffff);
        if (source) 
          {
            /* Assume this is an libgpg-error and try to map the codes
               back. */
            switch (code)
              {
              case 257: n = ASSUAN_General_Error          ; break;
              case 258: n = ASSUAN_Accept_Failed          ; break;
              case 259: n = ASSUAN_Connect_Failed         ; break;
              case 260: n = ASSUAN_Invalid_Response       ; break;
              case 261: n = ASSUAN_Invalid_Value          ; break;
              case 262: n = ASSUAN_Line_Not_Terminated    ; break;
              case 263: n = ASSUAN_Line_Too_Long          ; break;
              case 264: n = ASSUAN_Nested_Commands        ; break;
              case 265: n = ASSUAN_No_Data_Callback       ; break;
              case 266: n = ASSUAN_No_Inquire_Callback    ; break;
              case 267: n = ASSUAN_Not_A_Server           ; break;
              case  69: n = ASSUAN_Not_Implemented        ; break;
              case 280: n = ASSUAN_Parameter_Conflict     ; break;
              case 269: n = ASSUAN_Problem_Starting_Server; break;
              case 270: n = ASSUAN_Read_Error             ; break;
              case 271: n = ASSUAN_Write_Error            ; break;
              case  80: n = ASSUAN_Server_Fault           ; break;
              case 276: n = ASSUAN_Syntax_Error           ; break;
              case 273: n = ASSUAN_Too_Much_Data          ; break;
              case 274: n = ASSUAN_Unexpected_Command     ; break;
              case 275: n = ASSUAN_Unknown_Command        ; break;
              case 277: n = ASSUAN_Canceled               ; break;
              case 114: n = ASSUAN_Not_Confirmed          ; break;
              case ((1<<15)|86): n = ASSUAN_Out_Of_Core   ; break;
              default:  n = 0; break;
              }
            if (n)
              s = assuan_strerror (n);
            else
              {
                sprintf (buf, "ec=%u.%u", source, code ); 
                s=buf;
              }
          }
        else
          {
            sprintf (buf, "ec=%d", err ); 
            s=buf;
          }
      }
      break;
    }

  return s;
}

EOF