gpgme_get_sig_string_attr and gpgme_get_sig_key are now deprecated,
and gpgme_get_notation is removed.
+ * GpgmeTrustItem objects have now directly accessible data, so the
+ gpgme_trust_item_get_string_attr and gpgme_trust_item_get_ulong_attr
+ accessor functions are deprecated. Also, reference counting is
+ available through gpgme_trust_item_ref and gpgme_trust_item_unref
+ (the gpgme_trust_item_release alias for the latter is deprecated).
+
* Interface changes relative to the 0.4.0 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GpgmeIOCb CHANGED: Return type from void to GpgmeError.
gpgme_get_sig_string_attr DEPRECATED: Use verify result directly.
GPGME_SIG_STAT_* DEPRECATED: Use error value in sig status.
gpgme_get_sig_status DEPRECATED: Use verify result directly.
+GpgmeTrustItem CHANGED: Now has user accessible data members.
+gpgme_trust_item_ref NEW
+gpgme_trust_item_unref NEW
+gpgme_trust_item_release DEPRECATED: Use gpgme_trust_item_unref.
+gpgme_trust_item_get_string_attr DEPRECATED
+gpgme_trust_item_get_ulong_attr DEPRECATED
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Noteworthy changes in version 0.4.0 (2002-12-23)
+2003-04-29 Marcus Brinkmann <marcus@g10code.de>
+
+ * gpgme.texi (Trust Item Management): Add data members of
+ GpgmeTrustItem type.
+ (Information About Trust Items): Add note about obsoleteness.
+ (Manipulating Trust Items): Add gpgme_trust_item_ref and
+ gpgme_trust_item_unref.
+
2003-04-28 Marcus Brinkmann <marcus@g10code.de>
* gpgme.texi (Verify): Rewritten to take into account new and
@deftypefun void gpgme_key_unref (@w{GpgmeKey @var{key}})
@deftypefunx void gpgme_key_release (@w{GpgmeKey @var{key}})
-The function @code{gpgme_key_ref} releases a reference for the key
+The function @code{gpgme_key_unref} releases a reference for the key
@var{key}. If this was the last reference, the key will be destroyed
and all resources associated to it will be released.
@strong{Caution:} The trust items interface is experimental.
@deftp {Data type} GpgmeTrustItem
-The @code{GpgmeTrustItem} type is a handle for a trust item.
+The @code{GpgmeTrustItem} type is a pointer to a trust item object.
+It has the following members:
+
+@table @code
+@item char *keyid
+This is a string describing the key to which this trust items belongs.
+
+@item int type
+This is the type of the trust item. A value of 1 refers to a key, a
+value of 2 refers to a user ID.
+
+@item int level
+This is the trust level.
+
+@item char *otrust
+The owner trust if @code{type} is 1.
+
+@item char *val
+The calculated validity.
+
+@item char *name
+The user name if @code{type} is 2.
+@end table
@end deftp
@menu
@cindex trust item, attributes
@cindex attributes, of a trust item
+The following interfaces are deprecated and only provided for backward
+compatibility. Don't use them. They will be removed in a future
+version of @acronym{GPGME}.
+
Trust items have attributes which can be queried using the interfaces
below. The attribute identifiers are shared with those for key
attributes. @xref{Information About Keys}.
@subsection Manipulating Trust Items
@cindex trust item, manipulation
+@deftypefun void gpgme_trust_item_ref (@w{GpgmeTrustItem @var{item}})
+The function @code{gpgme_trust_item_ref} acquires an additional
+reference for the trust item @var{item}.
+@end deftypefun
+
+@deftypefun void gpgme_trust_item_unref (@w{GpgmeTrustItem @var{item}})
+The function @code{gpgme_trust_item_unref} releases a reference for
+the trust item @var{item}. If this was the last reference, the trust
+item will be destroyed and all resources associated to it will be
+released.
+@end deftypefun
+
+
+The following interface is deprecated and only provided for backward
+compatibility. Don't use it. It will be removed in a future version
+of @acronym{GPGME}.
+
@deftypefun void gpgme_trust_item_release (@w{GpgmeTrustItem @var{item}})
-The function @code{gpgme_trust_item_release} destroys a
-@code{GpgmeTrustItem} object and releases all associated resources.
+The function @code{gpgme_trust_item_release} is an alias for
+@code{gpgme_trust_item_unref}.
@end deftypefun
2003-04-29 Marcus Brinkmann <marcus@g10code.de>
+ * gpgme.h (struct _gpgme_trust_item): New structure.
+ (GpgmeTrustItem): New type.
+ (gpgme_trust_item_ref, gpgme_trust_item_unref): New prototypes.
+ * context.h (struct trust_queue_item_s): Remove structure.
+ (struct gpgme_context_s): Remove trust_queue member.
+ * Makefile.am (libgpgme_la_SOURCES): Add trust-item.c.
+ * trust-item.c: New file.
+ * trustlist.c: Do not include <stdio.h> or <time.h>, but
+ "gpgme.h".
+ (struct trust_queue_item_s): Change to new type op_data_t.
+ (trust_status_handler): Change first argument to void *.
+ (trust_colon_handler): Likewise.
+ (_gpgme_op_trustlist_event_cb): Use op_data_t type.
+ (gpgme_op_trustlist_start): Use op_data_t and rework error
+ handling.
+ (gpgme_op_trustlist_next): Use op_data_t.
+ (gpgme_trust_item_release): Remove function.
+ (gpgme_trust_item_get_string_attr): Likewise.
+ (gpgme_trust_item_get_int_attr): Likewise.
+
* verify.c (calc_sig_summary): Do not set GPGME_SIGSUM_SYS_ERROR
for bad signatures.
op-support.c \
encrypt.c encrypt-sign.c decrypt.c decrypt-verify.c verify.c \
sign.c passphrase.c progress.c \
- key.h key.c key-cache.c keylist.c trustlist.c \
+ key.c key-cache.c keylist.c trust-item.c trustlist.c \
import.c export.c genkey.c delete.c edit.c \
engine.h engine-backend.h engine.c rungpg.c status-table.h \
${gpgsm_components} sema.h io.h ${system_components} \
};
-struct trust_queue_item_s
-{
- struct trust_queue_item_s *next;
- GpgmeTrustItem item;
-};
-
-
/* Currently we need it at several places, so we put the definition
into this header file. */
struct gpgme_context_s
/* Something new is available. */
volatile int key_cond;
struct key_queue_item_s *key_queue;
- struct trust_queue_item_s *trust_queue;
/* The user provided passphrase callback and its hook value. */
GpgmePassphraseCb passphrase_cb;
struct gpgme_key_s;
typedef struct gpgme_key_s *GpgmeKey;
-/* A trust item. */
-struct gpgme_trust_item_s;
-typedef struct gpgme_trust_item_s *GpgmeTrustItem;
-
/* The error numbers used by GPGME. */
typedef enum
GpgmeAttr what,
const void *reserved, int idx);
-
-/* Release the trust item ITEM. */
-void gpgme_trust_item_release (GpgmeTrustItem item);
-
-/* Return the value of the attribute WHAT of ITEM, which has to be
- representable by a string. */
-const char *gpgme_trust_item_get_string_attr (GpgmeTrustItem item,
- GpgmeAttr what,
- const void *reserved, int idx);
-
-/* Return the value of the attribute WHAT of KEY, which has to be
- representable by an integer. IDX specifies a running index if the
- attribute appears more than once in the key. */
-int gpgme_trust_item_get_int_attr (GpgmeTrustItem item, GpgmeAttr what,
- const void *reserved, int idx);
\f
/* Crypto Operations. */
/* Terminate a pending keylist operation within CTX. */
GpgmeError gpgme_op_keylist_end (GpgmeCtx ctx);
+\f
+/* Trust items and operations. */
+
+struct _gpgme_trust_item
+{
+ /* Internal to GPGME, do not use. */
+ unsigned int _refs;
+
+ /* The key ID to which the trust item belongs. */
+ char *keyid;
+
+ /* Internal to GPGME, do not use. */
+ char _keyid[16 + 1];
+
+ /* The type of the trust item, 1 refers to a key, 2 to a user ID. */
+ int type;
+
+ /* The trust level. */
+ int level;
+
+ /* The owner trust if TYPE is 1. */
+ char *otrust;
+
+ /* Internal to GPGME, do not use. */
+ char _otrust[2];
+
+ /* The calculated validity. */
+ char *val;
+
+ /* Internal to GPGME, do not use. */
+ char _val[2];
+
+ /* The user name if TYPE is 2. */
+ char *name;
+};
+typedef struct _gpgme_trust_item *GpgmeTrustItem;
/* Start a trustlist operation within CTX, searching for trust items
which match PATTERN. */
/* Terminate a pending trustlist operation within CTX. */
GpgmeError gpgme_op_trustlist_end (GpgmeCtx ctx);
+/* Acquire a reference to ITEM. */
+void gpgme_trust_item_ref (GpgmeTrustItem item);
+
+/* Release a reference to ITEM. If this was the last one the trust
+ item is destroyed. */
+void gpgme_trust_item_unref (GpgmeTrustItem item);
+
+/* Release the trust item ITEM. */
+void gpgme_trust_item_release (GpgmeTrustItem item);
+/* Return the value of the attribute WHAT of ITEM, which has to be
+ representable by a string. */
+const char *gpgme_trust_item_get_string_attr (GpgmeTrustItem item,
+ GpgmeAttr what,
+ const void *reserved, int idx);
+
+/* Return the value of the attribute WHAT of KEY, which has to be
+ representable by an integer. IDX specifies a running index if the
+ attribute appears more than once in the key. */
+int gpgme_trust_item_get_int_attr (GpgmeTrustItem item, GpgmeAttr what,
+ const void *reserved, int idx);
+
+\f
/* Various functions. */
/* Check that the library fulfills the version requirement. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include <assert.h>
+#include "gpgme.h"
#include "util.h"
#include "context.h"
#include "ops.h"
-struct gpgme_trust_item_s
+\f
+struct trust_queue_item_s
{
- int level;
- char keyid[16+1];
- int type;
- char ot[2];
- char val[2];
- char *name;
+ struct trust_queue_item_s *next;
+ GpgmeTrustItem item;
};
-
-static GpgmeTrustItem
-trust_item_new (void)
+typedef struct
{
- GpgmeTrustItem item;
-
- item = calloc (1, sizeof *item);
- return item;
-}
+ /* Something new is available. */
+ int trust_cond;
+ struct trust_queue_item_s *trust_queue;
+} *op_data_t;
+\f
static GpgmeError
-trustlist_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args)
+trustlist_status_handler (void *priv, GpgmeStatusCode code, char *args)
{
- switch (code)
- {
- case GPGME_STATUS_EOF:
- break;
-
- default:
- break;
- }
return 0;
}
complete count NAME ist the username and only printed on U
lines. */
static GpgmeError
-trustlist_colon_handler (GpgmeCtx ctx, char *line)
+trustlist_colon_handler (void *priv, char *line)
{
+ GpgmeCtx ctx = (GpgmeCtx) priv;
+ GpgmeError err;
char *p, *pend;
int field = 0;
GpgmeTrustItem item = NULL;
switch (field)
{
case 1: /* level */
- item = trust_item_new ();
- if (!item)
- return GPGME_Out_Of_Core;
+ err = _gpgme_trust_item_new (&item);
+ if (err)
+ return err;
item->level = atoi (p);
break;
case 2: /* long keyid */
item->type = *p == 'K'? 1 : *p == 'U'? 2 : 0;
break;
case 5: /* owner trust */
- item->ot[0] = *p;
- item->ot[1] = 0;
+ item->_otrust[0] = *p;
break;
case 6: /* validity */
- item->val[0] = *p;
- item->val[1] = 0;
+ item->_val[0] = *p;
break;
case 9: /* user ID */
item->name = strdup (p);
if (!item->name) {
- gpgme_trust_item_release (item);
+ gpgme_trust_item_unref (item);
return GPGME_Out_Of_Core;
}
break;
_gpgme_op_trustlist_event_cb (void *data, GpgmeEventIO type, void *type_data)
{
GpgmeCtx ctx = (GpgmeCtx) data;
+ GpgmeError err;
+ op_data_t opd;
GpgmeTrustItem item = (GpgmeTrustItem) type_data;
struct trust_queue_item_s *q, *q2;
assert (type == GPGME_EVENT_NEXT_TRUSTITEM);
+ err = _gpgme_op_data_lookup (ctx, OPDATA_TRUSTLIST, (void **) &opd,
+ -1, NULL);
+ if (err)
+ return;
+
q = malloc (sizeof *q);
if (!q)
{
- gpgme_trust_item_release (item);
- /* FIXME */
- /* ctx->error = GPGME_Out_Of_Core; */
+ gpgme_trust_item_unref (item);
+ /* FIXME: GPGME_Out_Of_Core; */
return;
}
q->item = item;
q->next = NULL;
- /* FIXME: lock queue, keep a tail pointer */
- q2 = ctx->trust_queue;
+ /* FIXME: Use a tail pointer */
+ q2 = opd->trust_queue;
if (!q2)
- ctx->trust_queue = q;
+ opd->trust_queue = q;
else
{
while (q2->next)
q2->next = q;
}
/* FIXME: unlock queue */
- ctx->key_cond = 1;
+ opd->trust_cond = 1;
}
gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level)
{
GpgmeError err = 0;
+ op_data_t opd;
if (!pattern || !*pattern)
return GPGME_Invalid_Value;
err = _gpgme_op_reset (ctx, 2);
if (err)
- goto leave;
+ return err;
+
+ err = _gpgme_op_data_lookup (ctx, OPDATA_TRUSTLIST, (void **) &opd,
+ sizeof (*opd), NULL);
+ if (err)
+ return err;
_gpgme_engine_set_status_handler (ctx->engine,
trustlist_status_handler, ctx);
err = _gpgme_engine_set_colon_line_handler (ctx->engine,
trustlist_colon_handler, ctx);
if (err)
- goto leave;
-
- err =_gpgme_engine_op_trustlist (ctx->engine, pattern);
+ return err;
- leave:
- if (err)
- {
- _gpgme_engine_release (ctx->engine);
- ctx->engine = NULL;
- }
- return err;
+ return _gpgme_engine_op_trustlist (ctx->engine, pattern);
}
GpgmeError
gpgme_op_trustlist_next (GpgmeCtx ctx, GpgmeTrustItem *r_item)
{
+ GpgmeError err;
+ op_data_t opd;
struct trust_queue_item_s *q;
if (!r_item)
if (!ctx)
return GPGME_Invalid_Value;
- if (!ctx->trust_queue)
+ err = _gpgme_op_data_lookup (ctx, OPDATA_TRUSTLIST, (void **) &opd,
+ -1, NULL);
+ if (err)
+ return err;
+
+ if (!opd->trust_queue)
{
- GpgmeError err = _gpgme_wait_on_condition (ctx, &ctx->key_cond);
+ err = _gpgme_wait_on_condition (ctx, &opd->trust_cond);
if (err)
return err;
- if (!ctx->key_cond)
+ if (!opd->trust_cond)
return GPGME_EOF;
- ctx->key_cond = 0;
- assert (ctx->trust_queue);
+ opd->trust_cond = 0;
+ assert (opd->trust_queue);
}
- q = ctx->trust_queue;
- ctx->trust_queue = q->next;
+ q = opd->trust_queue;
+ opd->trust_queue = q->next;
*r_item = q->item;
free (q);
}
-/**
- * gpgme_op_trustlist_end:
- * @c: Context
- *
- * Ends the trustlist operation and allows to use the context for some
- * other operation next.
- **/
+/* Terminate a pending trustlist operation within CTX. */
GpgmeError
gpgme_op_trustlist_end (GpgmeCtx ctx)
{
return 0;
}
-
-
-void
-gpgme_trust_item_release (GpgmeTrustItem item)
-{
- if (!item)
- return;
- if (item->name)
- free (item->name);
- free (item);
-}
-
-
-const char *
-gpgme_trust_item_get_string_attr (GpgmeTrustItem item, GpgmeAttr what,
- const void *reserved, int idx)
-{
- const char *val = NULL;
-
- if (!item)
- return NULL;
- if (reserved)
- return NULL;
- if (idx)
- return NULL;
-
- switch (what)
- {
- case GPGME_ATTR_KEYID:
- val = item->keyid;
- break;
- case GPGME_ATTR_OTRUST:
- val = item->ot;
- break;
- case GPGME_ATTR_VALIDITY:
- val = item->val;
- break;
- case GPGME_ATTR_USERID:
- val = item->name;
- break;
- default:
- break;
- }
- return val;
-}
-
-
-int
-gpgme_trust_item_get_int_attr (GpgmeTrustItem item, GpgmeAttr what,
- const void *reserved, int idx)
-{
- int val = 0;
-
- if (!item)
- return 0;
- if (reserved)
- return 0;
- if (idx)
- return 0;
-
- switch (what)
- {
- case GPGME_ATTR_LEVEL:
- val = item->level;
- break;
- case GPGME_ATTR_TYPE:
- val = item->type;
- break;
- default:
- break;
- }
- return val;
-}
2003-04-29 Marcus Brinkmann <marcus@g10code.de>
+ * gpg/t-trustlist.c: Rewritten.
+
* gpg/t-verify.c (main): Rewritten.
* gpg/t-decrypt-verify.c: Rewritten.
* gpgsm/t-verify.c (main): Rewritten.
#include <gpgme.h>
-
+\f
#define fail_if_err(err) \
do \
{ \
-/* t-trustlist.c - regression test
- * Copyright (C) 2000 Werner Koch (dd9jn)
- * Copyright (C) 2001 g10 Code GmbH
- *
- * This file is part of GPGME.
- *
- * GPGME is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * GPGME is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
+/* t-trustlist.c - Regression test.
+ Copyright (C) 2000 Werner Koch (dd9jn)
+ Copyright (C) 2001, 2003 g10 Code GmbH
+
+ This file is part of GPGME.
+
+ GPGME is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ GPGME is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GPGME; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-#include <stdio.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
-#include <assert.h>
#include <gpgme.h>
-#define fail_if_err(a) do { if(a) { \
- fprintf (stderr, "%s:%d: GpgmeError %s\n", \
- __FILE__, __LINE__, gpgme_strerror(a)); \
- exit (1); } \
- } while(0)
-
-static void
-doit ( GpgmeCtx ctx, const char *pattern )
-{
- GpgmeError err;
- GpgmeTrustItem item;
-
- err = gpgme_op_trustlist_start (ctx, pattern, 0 );
- fail_if_err (err);
-
- while ( !(err = gpgme_op_trustlist_next ( ctx, &item )) ) {
- printf ("l=%d k=%s t=%d o=%s v=%s u=%s\n",
- gpgme_trust_item_get_int_attr (item, GPGME_ATTR_LEVEL, NULL, 0 ),
- gpgme_trust_item_get_string_attr (item, GPGME_ATTR_KEYID, NULL, 0 ),
- gpgme_trust_item_get_int_attr (item, GPGME_ATTR_TYPE, NULL, 0 ),
- gpgme_trust_item_get_string_attr (item, GPGME_ATTR_OTRUST, NULL, 0 ),
- gpgme_trust_item_get_string_attr (item, GPGME_ATTR_VALIDITY, NULL, 0 ),
- gpgme_trust_item_get_string_attr (item, GPGME_ATTR_USERID, NULL, 0 )
- );
- gpgme_trust_item_release (item);
- }
- if ( err != GPGME_EOF )
- fail_if_err (err);
-}
+\f
+#define fail_if_err(err) \
+ do \
+ { \
+ if (err) \
+ { \
+ fprintf (stderr, "%s:%d: GpgmeError %s\n", \
+ __FILE__, __LINE__, gpgme_strerror (err)); \
+ exit (1); \
+ } \
+ } \
+ while (0)
int
-main (int argc, char **argv )
+main (int argc, char *argv[])
{
- GpgmeCtx ctx;
- GpgmeError err;
- int loop = 0;
- const char *pattern;
-
- if( argc ) {
- argc--; argv++;
- }
-
- if (argc && !strcmp( *argv, "--loop" ) ) {
- loop = 1;
- argc--; argv++;
- }
- pattern = argc? *argv : "alice";
+ GpgmeCtx ctx;
+ GpgmeError err;
+ GpgmeTrustItem item;
+
+ err = gpgme_new (&ctx);
+ fail_if_err (err);
- err = gpgme_new (&ctx);
+ err = gpgme_op_trustlist_start (ctx, "alice", 0);
+ fail_if_err (err);
+
+ while (!(err = gpgme_op_trustlist_next (ctx, &item)))
+ {
+ printf ("l=%d k=%s t=%d o=%s v=%s u=%s\n",
+ gpgme_trust_item_get_int_attr (item, GPGME_ATTR_LEVEL, NULL, 0),
+ gpgme_trust_item_get_string_attr (item, GPGME_ATTR_KEYID, NULL, 0),
+ gpgme_trust_item_get_int_attr (item, GPGME_ATTR_TYPE, NULL, 0),
+ gpgme_trust_item_get_string_attr (item, GPGME_ATTR_OTRUST, NULL, 0),
+ gpgme_trust_item_get_string_attr (item, GPGME_ATTR_VALIDITY, NULL, 0),
+ gpgme_trust_item_get_string_attr (item, GPGME_ATTR_USERID, NULL, 0));
+ gpgme_trust_item_release (item);
+ }
+ if (err != GPGME_EOF)
fail_if_err (err);
- do {
- fprintf (stderr, "** pattern=`%s'\n", pattern );
- doit ( ctx, pattern );
- } while ( loop );
- gpgme_release (ctx);
- return 0;
+ gpgme_release (ctx);
+ return 0;
}
-
-
-