Line data Source code
1 : /* gpgme.c - GnuPG Made Easy.
2 : Copyright (C) 2000 Werner Koch (dd9jn)
3 : Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2012 g10 Code GmbH
4 :
5 : This file is part of GPGME.
6 :
7 : GPGME 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 : GPGME 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
18 : License along with this program; if not, write to the Free Software
19 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 : 02111-1307, USA. */
21 :
22 : #if HAVE_CONFIG_H
23 : #include <config.h>
24 : #endif
25 :
26 : #include <stdlib.h>
27 : #include <string.h>
28 :
29 : #include "util.h"
30 :
31 : struct status_table_s {
32 : const char *name;
33 : gpgme_status_code_t code;
34 : };
35 :
36 :
37 : /* Lexicographically sorted ('_' comes after any letter). You can use
38 : the Emacs command M-x sort-lines. But don't sweat it, the table is
39 : sorted at start up, too. */
40 : static struct status_table_s status_table[] =
41 : {
42 : { "ABORT", GPGME_STATUS_ABORT },
43 : { "ALREADY_SIGNED", GPGME_STATUS_ALREADY_SIGNED },
44 : { "ATTRIBUTE", GPGME_STATUS_ATTRIBUTE },
45 : { "BACKUP_KEY_CREATED", GPGME_STATUS_BACKUP_KEY_CREATED },
46 : { "BADARMOR", GPGME_STATUS_BADARMOR },
47 : { "BADMDC", GPGME_STATUS_BADMDC },
48 : { "BADSIG", GPGME_STATUS_BADSIG },
49 : { "BAD_PASSPHRASE", GPGME_STATUS_BAD_PASSPHRASE },
50 : { "BEGIN_DECRYPTION", GPGME_STATUS_BEGIN_DECRYPTION },
51 : { "BEGIN_ENCRYPTION", GPGME_STATUS_BEGIN_ENCRYPTION },
52 : { "BEGIN_SIGNING", GPGME_STATUS_BEGIN_SIGNING },
53 : { "BEGIN_STREAM", GPGME_STATUS_BEGIN_STREAM },
54 : { "CARDCTRL", GPGME_STATUS_CARDCTRL },
55 : { "DECRYPTION_FAILED", GPGME_STATUS_DECRYPTION_FAILED },
56 : { "DECRYPTION_INFO", GPGME_STATUS_DECRYPTION_INFO },
57 : { "DECRYPTION_OKAY", GPGME_STATUS_DECRYPTION_OKAY },
58 : { "DELETE_PROBLEM", GPGME_STATUS_DELETE_PROBLEM },
59 : { "DECRYPTION_COMPLIANCE_MODE", GPGME_STATUS_DECRYPTION_COMPLIANCE_MODE },
60 : { "ENC_TO", GPGME_STATUS_ENC_TO },
61 : { "END_DECRYPTION", GPGME_STATUS_END_DECRYPTION },
62 : { "END_ENCRYPTION", GPGME_STATUS_END_ENCRYPTION },
63 : { "END_STREAM", GPGME_STATUS_END_STREAM },
64 : { "ENTER", GPGME_STATUS_ENTER },
65 : { "ERRMDC", GPGME_STATUS_ERRMDC },
66 : { "ERROR", GPGME_STATUS_ERROR },
67 : { "ERRSIG", GPGME_STATUS_ERRSIG },
68 : { "EXPKEYSIG", GPGME_STATUS_EXPKEYSIG },
69 : { "EXPSIG", GPGME_STATUS_EXPSIG },
70 : { "FAILURE", GPGME_STATUS_FAILURE },
71 : { "FILE_DONE", GPGME_STATUS_FILE_DONE },
72 : { "FILE_ERROR", GPGME_STATUS_FILE_ERROR },
73 : { "FILE_START", GPGME_STATUS_FILE_START },
74 : { "GET_BOOL", GPGME_STATUS_GET_BOOL },
75 : { "GET_HIDDEN", GPGME_STATUS_GET_HIDDEN },
76 : { "GET_LINE", GPGME_STATUS_GET_LINE },
77 : { "GOODMDC", GPGME_STATUS_GOODMDC },
78 : { "GOODSIG", GPGME_STATUS_GOODSIG },
79 : { "GOOD_PASSPHRASE", GPGME_STATUS_GOOD_PASSPHRASE },
80 : { "GOT_IT", GPGME_STATUS_GOT_IT },
81 : { "IMPORTED", GPGME_STATUS_IMPORTED },
82 : { "IMPORT_OK", GPGME_STATUS_IMPORT_OK },
83 : { "IMPORT_PROBLEM", GPGME_STATUS_IMPORT_PROBLEM },
84 : { "IMPORT_RES", GPGME_STATUS_IMPORT_RES },
85 : { "INQUIRE_MAXLEN", GPGME_STATUS_INQUIRE_MAXLEN },
86 : { "INV_RECP", GPGME_STATUS_INV_RECP },
87 : { "INV_SGNR", GPGME_STATUS_INV_SGNR },
88 : { "KEYEXPIRED", GPGME_STATUS_KEYEXPIRED },
89 : { "KEYREVOKED", GPGME_STATUS_KEYREVOKED },
90 : { "KEY_CONSIDERED", GPGME_STATUS_KEY_CONSIDERED },
91 : { "KEY_CREATED", GPGME_STATUS_KEY_CREATED },
92 : { "KEY_NOT_CREATED", GPGME_STATUS_KEY_NOT_CREATED },
93 : { "LEAVE", GPGME_STATUS_LEAVE },
94 : { "MISSING_PASSPHRASE", GPGME_STATUS_MISSING_PASSPHRASE },
95 : { "MOUNTPOINT", GPGME_STATUS_MOUNTPOINT },
96 : { "NEED_PASSPHRASE", GPGME_STATUS_NEED_PASSPHRASE },
97 : { "NEED_PASSPHRASE_PIN", GPGME_STATUS_NEED_PASSPHRASE_PIN },
98 : { "NEED_PASSPHRASE_SYM", GPGME_STATUS_NEED_PASSPHRASE_SYM },
99 : { "NEWSIG", GPGME_STATUS_NEWSIG },
100 : { "NODATA", GPGME_STATUS_NODATA },
101 : { "NOTATION_DATA", GPGME_STATUS_NOTATION_DATA },
102 : { "NOTATION_FLAGS", GPGME_STATUS_NOTATION_FLAGS },
103 : { "NOTATION_NAME", GPGME_STATUS_NOTATION_NAME },
104 : { "NO_PUBKEY", GPGME_STATUS_NO_PUBKEY },
105 : { "NO_RECP", GPGME_STATUS_NO_RECP },
106 : { "NO_SECKEY", GPGME_STATUS_NO_SECKEY },
107 : { "NO_SGNR", GPGME_STATUS_NO_SGNR },
108 : { "PINENTRY_LAUNCHED", GPGME_STATUS_PINENTRY_LAUNCHED},
109 : { "PKA_TRUST_BAD", GPGME_STATUS_PKA_TRUST_BAD },
110 : { "PKA_TRUST_GOOD", GPGME_STATUS_PKA_TRUST_GOOD },
111 : { "PLAINTEXT", GPGME_STATUS_PLAINTEXT },
112 : { "PLAINTEXT_LENGTH", GPGME_STATUS_PLAINTEXT_LENGTH },
113 : { "POLICY_URL", GPGME_STATUS_POLICY_URL },
114 : { "PROGRESS", GPGME_STATUS_PROGRESS },
115 : { "REVKEYSIG", GPGME_STATUS_REVKEYSIG },
116 : { "RSA_OR_IDEA", GPGME_STATUS_RSA_OR_IDEA },
117 : { "SC_OP_FAILURE", GPGME_STATUS_SC_OP_FAILURE },
118 : { "SC_OP_SUCCESS", GPGME_STATUS_SC_OP_SUCCESS },
119 : { "SESSION_KEY", GPGME_STATUS_SESSION_KEY },
120 : { "SHM_GET", GPGME_STATUS_SHM_GET },
121 : { "SHM_GET_BOOL", GPGME_STATUS_SHM_GET_BOOL },
122 : { "SHM_GET_HIDDEN", GPGME_STATUS_SHM_GET_HIDDEN },
123 : { "SHM_INFO", GPGME_STATUS_SHM_INFO },
124 : { "SIGEXPIRED", GPGME_STATUS_SIGEXPIRED },
125 : { "SIG_CREATED", GPGME_STATUS_SIG_CREATED },
126 : { "SIG_ID", GPGME_STATUS_SIG_ID },
127 : { "SIG_SUBPACKET", GPGME_STATUS_SIG_SUBPACKET },
128 : { "SUCCESS", GPGME_STATUS_SUCCESS },
129 : { "TOFU_STATS", GPGME_STATUS_TOFU_STATS },
130 : { "TOFU_STATS_LONG", GPGME_STATUS_TOFU_STATS_LONG },
131 : { "TOFU_USER", GPGME_STATUS_TOFU_USER },
132 : { "TRUNCATED", GPGME_STATUS_TRUNCATED },
133 : { "TRUST_FULLY", GPGME_STATUS_TRUST_FULLY },
134 : { "TRUST_MARGINAL", GPGME_STATUS_TRUST_MARGINAL },
135 : { "TRUST_NEVER", GPGME_STATUS_TRUST_NEVER },
136 : { "TRUST_ULTIMATE", GPGME_STATUS_TRUST_ULTIMATE },
137 : { "TRUST_UNDEFINED", GPGME_STATUS_TRUST_UNDEFINED },
138 : { "UNEXPECTED", GPGME_STATUS_UNEXPECTED },
139 : { "USERID_HINT", GPGME_STATUS_USERID_HINT },
140 : { "VALIDSIG", GPGME_STATUS_VALIDSIG },
141 : { "VERIFICATION_COMPLIANCE_MODE", GPGME_STATUS_VERIFICATION_COMPLIANCE_MODE },
142 : {NULL, 0}
143 : };
144 :
145 :
146 : static int
147 69297 : status_cmp (const void *ap, const void *bp)
148 : {
149 69297 : const struct status_table_s *a = ap;
150 69297 : const struct status_table_s *b = bp;
151 :
152 69297 : return strcmp (a->name, b->name);
153 : }
154 :
155 :
156 : void
157 119 : _gpgme_status_init (void)
158 : {
159 119 : qsort (status_table,
160 : DIM(status_table) - 1, sizeof (status_table[0]),
161 : status_cmp);
162 119 : }
163 :
164 :
165 : gpgme_status_code_t
166 5460 : _gpgme_parse_status (const char *name)
167 : {
168 : struct status_table_s t, *r;
169 5460 : t.name = name;
170 5460 : r = bsearch (&t, status_table, DIM(status_table) - 1,
171 : sizeof t, status_cmp);
172 5460 : return r ? r->code : -1;
173 : }
174 :
175 :
176 : const char *
177 110 : _gpgme_status_to_string (gpgme_status_code_t code)
178 : {
179 : int i;
180 :
181 4764 : for (i=0; i < DIM(status_table); i++)
182 4764 : if (status_table[i].code == code)
183 110 : return status_table[i].name? status_table[i].name : "";
184 0 : return "status_code_lost";
185 : }
|