1 /* trustlist.c - key listing
2 * Copyright (C) 2000 Werner Koch (dd9jn)
4 * This file is part of GPGME.
6 * GPGME 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 * GPGME 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
32 #define my_isdigit(a) ( (a) >='0' && (a) <= '9' )
34 struct gpgme_trust_item_s {
49 item = xtrycalloc (1, sizeof *item);
56 trustlist_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
58 if ( ctx->out_of_core )
73 * This handler is used to parse the output of --list-trust-path:
75 * level:keyid:type:recno:ot:val:mc:cc:name:
76 * With TYPE = U for a user ID
78 * The RECNO is either the one of the dir record or the one of the uid record.
79 * OT is the the usual trust letter and only availabel on K lines.
80 * VAL is the calcualted validity
81 * MC is the marginal trust counter and only available on U lines
82 * CC is the same for the complete count
83 * NAME ist the username and only printed on U lines
86 trustlist_colon_handler ( GpgmeCtx ctx, char *line )
90 GpgmeTrustItem item = NULL;
91 struct trust_queue_item_s *q, *q2;
93 if ( ctx->out_of_core )
98 for (p = line; p; p = pend) {
100 pend = strchr (p, ':');
106 q = xtrymalloc ( sizeof *q );
108 ctx->out_of_core = 1;
112 q->item = item = trust_item_new ();
115 ctx->out_of_core = 1;
118 /* fixme: lock queue, keep a tail pointer */
119 if ( !(q2 = ctx->trust_queue) )
120 ctx->trust_queue = q;
122 for ( ; q2->next; q2 = q2->next )
126 /* fixme: unlock queue */
127 item->level = atoi (p);
129 case 2: /* long keyid */
130 if ( strlen (p) == DIM(item->keyid)-1 )
131 strcpy (item->keyid, p);
134 item->type = *p == 'K'? 1 : *p == 'U'? 2 : 0;
136 case 5: /* owner trust */
140 case 6: /* validity */
144 case 10: /* user ID */
145 item->name = xtrystrdup (p);
147 ctx->out_of_core = 1;
159 gpgme_op_trustlist_start ( GpgmeCtx c, const char *pattern, int max_level )
163 fail_on_pending_request( c );
164 if ( !pattern || !*pattern ) {
165 return mk_error (Invalid_Value);
170 _gpgme_release_result (c);
174 _gpgme_gpg_release ( c->gpg );
178 rc = _gpgme_gpg_new ( &c->gpg );
182 _gpgme_gpg_set_status_handler ( c->gpg, trustlist_status_handler, c );
183 rc = _gpgme_gpg_set_colon_line_handler ( c->gpg,
184 trustlist_colon_handler, c );
188 /* build the commandline */
189 _gpgme_gpg_add_arg ( c->gpg, "--with-colons" );
190 _gpgme_gpg_add_arg ( c->gpg, "--list-trust-path" );
192 /* Tell the gpg object about the data */
193 _gpgme_gpg_add_arg ( c->gpg, "--" );
194 _gpgme_gpg_add_arg ( c->gpg, pattern );
196 /* and kick off the process */
197 rc = _gpgme_gpg_spawn ( c->gpg, c );
202 _gpgme_gpg_release ( c->gpg ); c->gpg = NULL;
209 gpgme_op_trustlist_next ( GpgmeCtx c, GpgmeTrustItem *r_item )
211 struct trust_queue_item_s *q;
214 return mk_error (Invalid_Value);
217 return mk_error (Invalid_Value);
219 return mk_error (No_Request);
220 if ( c->out_of_core )
221 return mk_error (Out_Of_Core);
223 if ( !c->trust_queue ) {
224 _gpgme_wait_on_condition (c, 1, &c->key_cond );
225 if ( c->out_of_core )
226 return mk_error (Out_Of_Core);
228 return mk_error (EOF);
230 assert ( c->trust_queue );
233 c->trust_queue = q->next;
242 gpgme_trust_item_release ( GpgmeTrustItem item )
252 gpgme_trust_item_get_string_attr ( GpgmeTrustItem item, GpgmeAttr what,
253 const void *reserved, int idx )
255 const char *val = NULL;
265 case GPGME_ATTR_KEYID:
268 case GPGME_ATTR_OTRUST:
271 case GPGME_ATTR_VALIDITY:
274 case GPGME_ATTR_USERID:
285 gpgme_trust_item_get_int_attr ( GpgmeTrustItem item, GpgmeAttr what,
286 const void *reserved, int idx )
298 case GPGME_ATTR_LEVEL:
301 case GPGME_ATTR_TYPE: