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 = xtrycalloc (1, sizeof *item);
55 trustlist_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
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;
90 struct trust_queue_item_s *q, *q2;
97 for (p = line; p; p = pend)
100 pend = strchr (p, ':');
107 q = xtrymalloc (sizeof *q);
110 ctx->error = mk_error (Out_Of_Core);
114 q->item = item = trust_item_new ();
118 ctx->error = mk_error (Out_Of_Core);
121 /* fixme: lock queue, keep a tail pointer */
122 q2 = ctx->trust_queue;
124 ctx->trust_queue = q;
131 /* fixme: unlock queue */
132 item->level = atoi (p);
134 case 2: /* long keyid */
135 if (strlen (p) == DIM(item->keyid) - 1)
136 strcpy (item->keyid, p);
139 item->type = *p == 'K'? 1 : *p == 'U'? 2 : 0;
141 case 5: /* owner trust */
145 case 6: /* validity */
149 case 9: /* user ID */
150 item->name = xtrystrdup (p);
152 ctx->error = mk_error (Out_Of_Core);
163 gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level)
167 if (!pattern || !*pattern)
168 return mk_error (Invalid_Value);
170 err = _gpgme_op_reset (ctx, 0);
174 err = _gpgme_engine_set_colon_line_handler (ctx->engine,
175 trustlist_colon_handler, ctx);
179 err =_gpgme_engine_op_trustlist (ctx->engine, pattern);
181 if (!err) /* And kick off the process. */
182 err = _gpgme_engine_start (ctx->engine, ctx);
188 _gpgme_engine_release (ctx->engine);
196 gpgme_op_trustlist_next (GpgmeCtx ctx, GpgmeTrustItem *r_item)
198 struct trust_queue_item_s *q;
201 return mk_error (Invalid_Value);
204 return mk_error (Invalid_Value);
206 return mk_error (No_Request);
210 if (!ctx->trust_queue)
212 _gpgme_wait_on_condition (ctx, 1, &ctx->key_cond);
216 return mk_error (EOF);
218 assert (ctx->trust_queue);
220 q = ctx->trust_queue;
221 ctx->trust_queue = q->next;
230 * gpgme_op_trustlist_end:
233 * Ends the trustlist operation and allows to use the context for some
234 * other operation next.
237 gpgme_op_trustlist_end (GpgmeCtx ctx)
240 return mk_error (Invalid_Value);
242 return mk_error (No_Request);
252 gpgme_trust_item_release (GpgmeTrustItem item)
262 gpgme_trust_item_get_string_attr (GpgmeTrustItem item, GpgmeAttr what,
263 const void *reserved, int idx)
265 const char *val = NULL;
276 case GPGME_ATTR_KEYID:
279 case GPGME_ATTR_OTRUST:
282 case GPGME_ATTR_VALIDITY:
285 case GPGME_ATTR_USERID:
296 gpgme_trust_item_get_int_attr (GpgmeTrustItem item, GpgmeAttr what,
297 const void *reserved, int idx)
310 case GPGME_ATTR_LEVEL:
313 case GPGME_ATTR_TYPE: