1
/* maperror.c - Error mapping
2
* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4
* This file is part of GnuPG.
6
* GnuPG is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* GnuPG is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
35
/* Map Assuan error code ERR to an GPG_ERR_ code. We need to
36
distinguish between genuine (and legacy) Assuan error codes and
37
application error codes shared with all GnuPG modules. The rule is
38
simple: All errors with a gpg_err_source of UNKNOWN are genuine
39
Assuan codes all others are passed verbatim through. */
41
map_assuan_err_with_source (int source, int err)
45
if (gpg_err_source (err))
50
case -1: ec = GPG_ERR_EOF; break;
51
case 0: ec = 0; break;
53
case ASSUAN_Canceled: ec = GPG_ERR_CANCELED; break;
54
case ASSUAN_Invalid_Index: ec = GPG_ERR_INV_INDEX; break;
56
case ASSUAN_Not_Implemented: ec = GPG_ERR_NOT_IMPLEMENTED; break;
57
case ASSUAN_Server_Fault: ec = GPG_ERR_ASSUAN_SERVER_FAULT; break;
58
case ASSUAN_No_Public_Key: ec = GPG_ERR_NO_PUBKEY; break;
59
case ASSUAN_No_Secret_Key: ec = GPG_ERR_NO_SECKEY; break;
61
case ASSUAN_Cert_Revoked: ec = GPG_ERR_CERT_REVOKED; break;
62
case ASSUAN_No_CRL_For_Cert: ec = GPG_ERR_NO_CRL_KNOWN; break;
63
case ASSUAN_CRL_Too_Old: ec = GPG_ERR_CRL_TOO_OLD; break;
65
case ASSUAN_Not_Trusted: ec = GPG_ERR_NOT_TRUSTED; break;
67
case ASSUAN_Card_Error: ec = GPG_ERR_CARD; break;
68
case ASSUAN_Invalid_Card: ec = GPG_ERR_INV_CARD; break;
69
case ASSUAN_No_PKCS15_App: ec = GPG_ERR_NO_PKCS15_APP; break;
70
case ASSUAN_Card_Not_Present: ec= GPG_ERR_CARD_NOT_PRESENT; break;
71
case ASSUAN_Not_Confirmed: ec = GPG_ERR_NOT_CONFIRMED; break;
72
case ASSUAN_Invalid_Id: ec = GPG_ERR_INV_ID; break;
74
case ASSUAN_Locale_Problem: ec = GPG_ERR_LOCALE_PROBLEM; break;
77
ec = err < 100? GPG_ERR_ASSUAN_SERVER_FAULT : GPG_ERR_ASSUAN;
80
return gpg_err_make (source, ec);
83
/* Map GPG_xERR_xx error codes to Assuan status codes */
85
map_to_assuan_status (int rc)
87
gpg_err_code_t ec = gpg_err_code (rc);
88
gpg_err_source_t es = gpg_err_source (rc);
94
es = GPG_ERR_SOURCE_USER_4; /* This should not happen, but we
95
need to make sure to pass a new
96
Assuan errorcode along. */
97
log_debug ("map_to_assuan_status called with no error source\n");
101
ec = GPG_ERR_NO_DATA; /* That used to be ASSUAN_No_Data_Available. */
103
return gpg_err_make (es, ec);