2002-01-15 Marcus Brinkmann <marcus@g10code.de>

* trustlist.c: Various source clean ups.
	(my_isdigit): Removed.
	(gpgme_op_trustlist_end): New function.
This commit is contained in:
Marcus Brinkmann 2002-01-16 00:44:11 +00:00
parent d7c0314674
commit f3d11ead88
2 changed files with 198 additions and 161 deletions

View File

@ -1,3 +1,9 @@
2002-01-15 Marcus Brinkmann <marcus@g10code.de>
* trustlist.c: Various source clean ups.
(my_isdigit): Removed.
(gpgme_op_trustlist_end): New function.
2002-01-13 Marcus Brinkmann <marcus@g10code.de> 2002-01-13 Marcus Brinkmann <marcus@g10code.de>
* gpgme.c: Various source clean ups, like renaming C to CTX where * gpgme.c: Various source clean ups, like renaming C to CTX where

View File

@ -1,6 +1,6 @@
/* trustlist.c - key listing /* trustlist.c - key listing
* Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH * Copyright (C) 2001, 2002 g10 Code GmbH
* *
* This file is part of GPGME. * This file is part of GPGME.
* *
@ -30,46 +30,44 @@
#include "context.h" #include "context.h"
#include "ops.h" #include "ops.h"
#define my_isdigit(a) ( (a) >='0' && (a) <= '9' ) struct gpgme_trust_item_s
{
struct gpgme_trust_item_s { int level;
int level; char keyid[16+1];
char keyid[16+1]; int type;
int type; char ot[2];
char ot[2]; char val[2];
char val[2]; char *name;
char *name;
}; };
static GpgmeTrustItem static GpgmeTrustItem
trust_item_new (void) trust_item_new (void)
{ {
GpgmeTrustItem item; GpgmeTrustItem item;
item = xtrycalloc (1, sizeof *item); item = xtrycalloc (1, sizeof *item);
return item; return item;
} }
static void static void
trustlist_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args ) trustlist_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args)
{ {
if ( ctx->out_of_core ) if (ctx->out_of_core)
return; return;
switch (code) { switch (code)
case STATUS_EOF: {
break; case STATUS_EOF:
break;
default: default:
break; break;
} }
} }
/* /*
* This handler is used to parse the output of --list-trust-path: * This handler is used to parse the output of --list-trust-path:
* Format: * Format:
@ -84,76 +82,83 @@ trustlist_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args )
* NAME ist the username and only printed on U lines * NAME ist the username and only printed on U lines
*/ */
static void static void
trustlist_colon_handler ( GpgmeCtx ctx, char *line ) trustlist_colon_handler (GpgmeCtx ctx, char *line)
{ {
char *p, *pend; char *p, *pend;
int field = 0; int field = 0;
GpgmeTrustItem item = NULL; GpgmeTrustItem item = NULL;
struct trust_queue_item_s *q, *q2; struct trust_queue_item_s *q, *q2;
if ( ctx->out_of_core ) if (ctx->out_of_core)
return; return;
if (!line) if (!line)
return; /* EOF */ return; /* EOF */
for (p = line; p; p = pend) { for (p = line; p; p = pend)
field++; {
pend = strchr (p, ':'); field++;
if (pend) pend = strchr (p, ':');
*pend++ = 0; if (pend)
*pend++ = 0;
switch (field) { switch (field)
case 1: /* level */ {
q = xtrymalloc ( sizeof *q ); case 1: /* level */
if ( !q ) { q = xtrymalloc (sizeof *q);
ctx->out_of_core = 1; if (!q)
return; {
ctx->out_of_core = 1;
return;
} }
q->next = NULL; q->next = NULL;
q->item = item = trust_item_new (); q->item = item = trust_item_new ();
if (!q->item) { if (!q->item)
xfree (q); {
ctx->out_of_core = 1; xfree (q);
return; ctx->out_of_core = 1;
return;
} }
/* fixme: lock queue, keep a tail pointer */ /* fixme: lock queue, keep a tail pointer */
if ( !(q2 = ctx->trust_queue) ) q2 = ctx->trust_queue;
ctx->trust_queue = q; if (!q2)
else { ctx->trust_queue = q;
for ( ; q2->next; q2 = q2->next ) else
; {
q2->next = q; while (q2->next)
q2 = q2->next;
q2->next = q;
} }
/* fixme: unlock queue */ /* fixme: unlock queue */
item->level = atoi (p); item->level = atoi (p);
break; break;
case 2: /* long keyid */ case 2: /* long keyid */
if ( strlen (p) == DIM(item->keyid)-1 ) if (strlen (p) == DIM(item->keyid) - 1)
strcpy (item->keyid, p); strcpy (item->keyid, p);
break; break;
case 3: /* type */ case 3: /* type */
item->type = *p == 'K'? 1 : *p == 'U'? 2 : 0; item->type = *p == 'K'? 1 : *p == 'U'? 2 : 0;
break; break;
case 5: /* owner trust */ case 5: /* owner trust */
item->ot[0] = *p; item->ot[0] = *p;
item->ot[1] = 0; item->ot[1] = 0;
break; break;
case 6: /* validity */ case 6: /* validity */
item->val[0] = *p; item->val[0] = *p;
item->val[1] = 0; item->val[1] = 0;
break; break;
case 9: /* user ID */ case 9: /* user ID */
item->name = xtrystrdup (p); item->name = xtrystrdup (p);
if (!item->name) if (!item->name)
ctx->out_of_core = 1; ctx->out_of_core = 1;
break; break;
} }
} }
if (field) if (field)
ctx->key_cond = 1; ctx->key_cond = 1;
} }
GpgmeError GpgmeError
gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level) gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level)
{ {
@ -173,7 +178,7 @@ gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level)
_gpgme_engine_release (ctx->engine); _gpgme_engine_release (ctx->engine);
ctx->engine = NULL; ctx->engine = NULL;
} }
err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS err = _gpgme_engine_new (ctx->use_cms ? GPGME_PROTOCOL_CMS
: GPGME_PROTOCOL_OpenPGP, &ctx->engine); : GPGME_PROTOCOL_OpenPGP, &ctx->engine);
if (err) if (err)
@ -191,114 +196,140 @@ gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level)
err = _gpgme_engine_start (ctx->engine, ctx); err = _gpgme_engine_start (ctx->engine, ctx);
leave: leave:
if (err) { if (err)
ctx->pending = 0; {
_gpgme_engine_release (ctx->engine); ctx->pending = 0;
ctx->engine = NULL; _gpgme_engine_release (ctx->engine);
} ctx->engine = NULL;
}
return err; return err;
} }
GpgmeError GpgmeError
gpgme_op_trustlist_next ( GpgmeCtx c, GpgmeTrustItem *r_item ) gpgme_op_trustlist_next (GpgmeCtx c, GpgmeTrustItem *r_item)
{ {
struct trust_queue_item_s *q; struct trust_queue_item_s *q;
if (!r_item) if (!r_item)
return mk_error (Invalid_Value); return mk_error (Invalid_Value);
*r_item = NULL; *r_item = NULL;
if (!c) if (!c)
return mk_error (Invalid_Value); return mk_error (Invalid_Value);
if ( !c->pending ) if (!c->pending)
return mk_error (No_Request); return mk_error (No_Request);
if ( c->out_of_core ) if (c->out_of_core)
return mk_error (Out_Of_Core); return mk_error (Out_Of_Core);
if ( !c->trust_queue ) { if (!c->trust_queue)
_gpgme_wait_on_condition (c, 1, &c->key_cond ); {
if ( c->out_of_core ) _gpgme_wait_on_condition (c, 1, &c->key_cond);
return mk_error (Out_Of_Core); if (c->out_of_core)
if ( !c->key_cond ) return mk_error (Out_Of_Core);
return mk_error (EOF); if (!c->key_cond)
c->key_cond = 0; return mk_error (EOF);
assert ( c->trust_queue ); c->key_cond = 0;
assert (c->trust_queue);
} }
q = c->trust_queue; q = c->trust_queue;
c->trust_queue = q->next; c->trust_queue = q->next;
*r_item = q->item; *r_item = q->item;
xfree (q); xfree (q);
return 0; return 0;
}
/**
* gpgme_op_trustlist_end:
* @c: Context
*
* Ends the trustlist operation and allows to use the context for some
* other operation next.
**/
GpgmeError
gpgme_op_trustlist_end (GpgmeCtx ctx)
{
if (!ctx)
return mk_error (Invalid_Value);
if (!ctx->pending)
return mk_error (No_Request);
if (ctx->out_of_core)
return mk_error (Out_Of_Core);
ctx->pending = 0;
return 0;
} }
void void
gpgme_trust_item_release ( GpgmeTrustItem item ) gpgme_trust_item_release (GpgmeTrustItem item)
{ {
if (!item) if (!item)
return; return;
xfree (item->name); xfree (item->name);
xfree (item); xfree (item);
} }
const char * const char *
gpgme_trust_item_get_string_attr ( GpgmeTrustItem item, GpgmeAttr what, gpgme_trust_item_get_string_attr (GpgmeTrustItem item, GpgmeAttr what,
const void *reserved, int idx ) const void *reserved, int idx)
{ {
const char *val = NULL; const char *val = NULL;
if (!item) if (!item)
return NULL; return NULL;
if (reserved) if (reserved)
return NULL; return NULL;
if (idx) if (idx)
return NULL; return NULL;
switch (what) { switch (what)
case GPGME_ATTR_KEYID: {
val = item->keyid; case GPGME_ATTR_KEYID:
break; val = item->keyid;
case GPGME_ATTR_OTRUST: break;
val = item->ot; case GPGME_ATTR_OTRUST:
break; val = item->ot;
case GPGME_ATTR_VALIDITY: break;
val = item->val; case GPGME_ATTR_VALIDITY:
break; val = item->val;
case GPGME_ATTR_USERID: break;
val = item->name; case GPGME_ATTR_USERID:
break; val = item->name;
default: break;
break; default:
break;
} }
return val; return val;
} }
int int
gpgme_trust_item_get_int_attr ( GpgmeTrustItem item, GpgmeAttr what, gpgme_trust_item_get_int_attr (GpgmeTrustItem item, GpgmeAttr what,
const void *reserved, int idx ) const void *reserved, int idx)
{ {
int val = 0; int val = 0;
if (!item)
return 0;
if (reserved)
return 0;
if (idx)
return 0;
if (!item) switch (what)
return 0; {
if (reserved) case GPGME_ATTR_LEVEL:
return 0; val = item->level;
if (idx) break;
return 0; case GPGME_ATTR_TYPE:
val = item->type;
switch (what) { break;
case GPGME_ATTR_LEVEL: default:
val = item->level; break;
break;
case GPGME_ATTR_TYPE:
val = item->type;
break;
default:
break;
} }
return val; return val;
} }