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
36 /* Map Assuan error code ERR to an GPG_ERR_ code. We need to
37 distinguish between genuine (and legacy) Assuan error codes and
38 application error codes shared with all GnuPG modules. The rule is
39 simple: All errors with a gpg_err_source of UNKNOWN are genuine
40 Assuan codes all others are passed verbatim through. */
42 map_assuan_err (int err)
46 if (gpg_err_source (err))
51 case -1: ec = GPG_ERR_EOF; break;
52 case 0: ec = 0; break;
54 case ASSUAN_Canceled: ec = GPG_ERR_CANCELED; break;
55 case ASSUAN_Invalid_Index: ec = GPG_ERR_INV_INDEX; break;
57 case ASSUAN_Not_Implemented: ec = GPG_ERR_NOT_IMPLEMENTED; break;
58 case ASSUAN_Server_Fault: ec = GPG_ERR_ASSUAN_SERVER_FAULT; break;
59 case ASSUAN_No_Public_Key: ec = GPG_ERR_NO_PUBKEY; break;
60 case ASSUAN_No_Secret_Key: ec = GPG_ERR_NO_SECKEY; break;
62 case ASSUAN_Cert_Revoked: ec = GPG_ERR_CERT_REVOKED; break;
63 case ASSUAN_No_CRL_For_Cert: ec = GPG_ERR_NO_CRL_KNOWN; break;
64 case ASSUAN_CRL_Too_Old: ec = GPG_ERR_CRL_TOO_OLD; break;
66 case ASSUAN_Not_Trusted: ec = GPG_ERR_NOT_TRUSTED; break;
68 case ASSUAN_Card_Error: ec = GPG_ERR_CARD; break;
69 case ASSUAN_Invalid_Card: ec = GPG_ERR_INV_CARD; break;
70 case ASSUAN_No_PKCS15_App: ec = GPG_ERR_NO_PKCS15_APP; break;
71 case ASSUAN_Card_Not_Present: ec= GPG_ERR_CARD_NOT_PRESENT; break;
72 case ASSUAN_Not_Confirmed: ec = GPG_ERR_NOT_CONFIRMED; break;
73 case ASSUAN_Invalid_Id: ec = GPG_ERR_INV_ID; break;
75 #if 0 /* FIXME: Enable this after releasing libgpg error 0.7 */
76 case ASSUAN_Locale_Problem: ec = GPG_ERR_LOCALE_PROBLEM; break;
80 ec = err < 100? GPG_ERR_ASSUAN_SERVER_FAULT : GPG_ERR_ASSUAN;
83 return gpg_err_make (GPG_ERR_SOURCE_UNKNOWN, ec);
86 /* Map GPG_xERR_xx error codes to Assuan status codes */
88 map_to_assuan_status (int rc)
90 gpg_err_code_t ec = gpg_err_code (rc);
91 gpg_err_source_t es = gpg_err_source (rc);
97 es = GPG_ERR_SOURCE_USER_4; /* This should not happen, but we
98 need to make sure to pass a new
99 Assuan errorcode along. */
100 log_debug ("map_to_assuan_status called with no error source\n");
104 ec = GPG_ERR_NO_DATA; /* That used to be ASSUAN_No_Data_Available. */
106 return gpg_err_make (es, ec);