1 /* trustlist.c - key listing
2 * Copyright (C) 2000 Werner Koch (dd9jn)
3 * Copyright (C) 2001, 2002 g10 Code GmbH
5 * This file is part of GPGME.
7 * GPGME is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * GPGME is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
33 struct gpgme_trust_item_s
49 item = calloc (1, sizeof *item);
55 trustlist_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args)
62 case GPGME_STATUS_EOF:
72 * This handler is used to parse the output of --list-trust-path:
74 * level:keyid:type:recno:ot:val:mc:cc:name:
75 * With TYPE = U for a user ID
77 * The RECNO is either the one of the dir record or the one of the uid record.
78 * OT is the the usual trust letter and only availabel on K lines.
79 * VAL is the calcualted validity
80 * MC is the marginal trust counter and only available on U lines
81 * CC is the same for the complete count
82 * NAME ist the username and only printed on U lines
85 trustlist_colon_handler (GpgmeCtx ctx, char *line)
89 GpgmeTrustItem item = NULL;
96 for (p = line; p; p = pend)
99 pend = strchr (p, ':');
106 item = trust_item_new ();
109 ctx->error = mk_error (Out_Of_Core);
112 item->level = atoi (p);
114 case 2: /* long keyid */
115 if (strlen (p) == DIM(item->keyid) - 1)
116 strcpy (item->keyid, p);
119 item->type = *p == 'K'? 1 : *p == 'U'? 2 : 0;
121 case 5: /* owner trust */
125 case 6: /* validity */
129 case 9: /* user ID */
130 item->name = strdup (p);
132 ctx->error = mk_error (Out_Of_Core);
138 _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_NEXT_TRUSTITEM, item);
143 _gpgme_op_trustlist_event_cb (void *data, GpgmeEventIO type, void *type_data)
145 GpgmeCtx ctx = (GpgmeCtx) data;
146 GpgmeTrustItem item = (GpgmeTrustItem) type_data;
147 struct trust_queue_item_s *q, *q2;
149 assert (type == GPGME_EVENT_NEXT_KEY);
151 q = malloc (sizeof *q);
154 gpgme_trust_item_release (item);
155 ctx->error = mk_error (Out_Of_Core);
160 /* FIXME: lock queue, keep a tail pointer */
161 q2 = ctx->trust_queue;
163 ctx->trust_queue = q;
170 /* FIXME: unlock queue */
176 gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level)
180 if (!pattern || !*pattern)
181 return mk_error (Invalid_Value);
183 err = _gpgme_op_reset (ctx, 2);
187 _gpgme_engine_set_status_handler (ctx->engine,
188 trustlist_status_handler, ctx);
189 err = _gpgme_engine_set_colon_line_handler (ctx->engine,
190 trustlist_colon_handler, ctx);
194 err =_gpgme_engine_op_trustlist (ctx->engine, pattern);
196 if (!err) /* And kick off the process. */
197 err = _gpgme_engine_start (ctx->engine, ctx);
203 _gpgme_engine_release (ctx->engine);
211 gpgme_op_trustlist_next (GpgmeCtx ctx, GpgmeTrustItem *r_item)
213 struct trust_queue_item_s *q;
216 return mk_error (Invalid_Value);
219 return mk_error (Invalid_Value);
221 return mk_error (No_Request);
225 if (!ctx->trust_queue)
227 GpgmeError err = _gpgme_wait_on_condition (ctx, &ctx->key_cond);
235 /* The operation finished. Because not all keys might have
236 been returned to the caller yet, we just reset the
237 pending flag to 1. This will cause us to call
238 _gpgme_wait_on_condition without any active file
239 descriptors, but that is a no-op, so it is safe. */
245 return mk_error (EOF);
248 assert (ctx->trust_queue);
250 q = ctx->trust_queue;
251 ctx->trust_queue = q->next;
260 * gpgme_op_trustlist_end:
263 * Ends the trustlist operation and allows to use the context for some
264 * other operation next.
267 gpgme_op_trustlist_end (GpgmeCtx ctx)
270 return mk_error (Invalid_Value);
272 return mk_error (No_Request);
282 gpgme_trust_item_release (GpgmeTrustItem item)
292 gpgme_trust_item_get_string_attr (GpgmeTrustItem item, GpgmeAttr what,
293 const void *reserved, int idx)
295 const char *val = NULL;
306 case GPGME_ATTR_KEYID:
309 case GPGME_ATTR_OTRUST:
312 case GPGME_ATTR_VALIDITY:
315 case GPGME_ATTR_USERID:
326 gpgme_trust_item_get_int_attr (GpgmeTrustItem item, GpgmeAttr what,
327 const void *reserved, int idx)
340 case GPGME_ATTR_LEVEL:
343 case GPGME_ATTR_TYPE: