1 /* trust-item.c - Trust item objects.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2003 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 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, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GPGME; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 /* Protects all reference counters in trust items. All other accesses
35 to a trust item are either read only or happen before the trust
36 item is available to the user. */
37 DEFINE_STATIC_LOCK (trust_item_ref_lock);
40 /* Create a new trust item. */
42 _gpgme_trust_item_new (gpgme_trust_item_t *r_item)
44 gpgme_trust_item_t item;
46 item = calloc (1, sizeof *item);
48 return gpg_error_from_errno (errno);
50 item->keyid = item->_keyid;
51 item->_keyid[16] = '\0';
52 item->owner_trust = item->_owner_trust;
53 item->_owner_trust[1] = '\0';
54 item->validity = item->_validity;
55 item->_validity[1] = '\0';
61 /* Acquire a reference to ITEM. */
63 gpgme_trust_item_ref (gpgme_trust_item_t item)
65 LOCK (trust_item_ref_lock);
67 UNLOCK (trust_item_ref_lock);
71 /* gpgme_trust_item_unref releases the trust item object. Note that
72 this function may not do an actual release if there are other
73 shallow copies of the object. You have to call this function for
74 every newly created trust item object as well as for every
75 gpgme_trust_item_ref() done on the trust item object. */
77 gpgme_trust_item_unref (gpgme_trust_item_t item)
79 LOCK (trust_item_ref_lock);
80 assert (item->_refs > 0);
83 UNLOCK (trust_item_ref_lock);
86 UNLOCK (trust_item_ref_lock);
94 /* Compatibility interfaces. */
96 gpgme_trust_item_release (gpgme_trust_item_t item)
98 gpgme_trust_item_unref (item);
101 /* Return the value of the attribute WHAT of ITEM, which has to be
102 representable by a string. */
103 const char *gpgme_trust_item_get_string_attr (gpgme_trust_item_t item,
105 const void *reserved, int idx)
107 const char *val = NULL;
118 case GPGME_ATTR_KEYID:
122 case GPGME_ATTR_OTRUST:
123 val = item->owner_trust;
126 case GPGME_ATTR_VALIDITY:
127 val = item->validity;
130 case GPGME_ATTR_USERID:
141 /* Return the value of the attribute WHAT of KEY, which has to be
142 representable by an integer. IDX specifies a running index if the
143 attribute appears more than once in the key. */
144 int gpgme_trust_item_get_int_attr (gpgme_trust_item_t item, _gpgme_attr_t what,
145 const void *reserved, int idx)
158 case GPGME_ATTR_LEVEL:
162 case GPGME_ATTR_TYPE: