1 /* trust-item.c - Trust item objects.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2003, 2004 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 Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (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 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35 /* Protects all reference counters in trust items. All other accesses
36 to a trust item are either read only or happen before the trust
37 item is available to the user. */
38 DEFINE_STATIC_LOCK (trust_item_ref_lock);
41 /* Create a new trust item. */
43 _gpgme_trust_item_new (gpgme_trust_item_t *r_item)
45 gpgme_trust_item_t item;
47 item = calloc (1, sizeof *item);
49 return gpg_error_from_errno (errno);
51 item->keyid = item->_keyid;
52 item->_keyid[16] = '\0';
53 item->owner_trust = item->_owner_trust;
54 item->_owner_trust[1] = '\0';
55 item->validity = item->_validity;
56 item->_validity[1] = '\0';
62 /* Acquire a reference to ITEM. */
64 gpgme_trust_item_ref (gpgme_trust_item_t item)
66 LOCK (trust_item_ref_lock);
68 UNLOCK (trust_item_ref_lock);
72 /* gpgme_trust_item_unref releases the trust item object. Note that
73 this function may not do an actual release if there are other
74 shallow copies of the object. You have to call this function for
75 every newly created trust item object as well as for every
76 gpgme_trust_item_ref() done on the trust item object. */
78 gpgme_trust_item_unref (gpgme_trust_item_t item)
80 LOCK (trust_item_ref_lock);
81 assert (item->_refs > 0);
84 UNLOCK (trust_item_ref_lock);
87 UNLOCK (trust_item_ref_lock);
95 /* Compatibility interfaces. */
97 gpgme_trust_item_release (gpgme_trust_item_t item)
99 gpgme_trust_item_unref (item);
102 /* Return the value of the attribute WHAT of ITEM, which has to be
103 representable by a string. */
104 const char *gpgme_trust_item_get_string_attr (gpgme_trust_item_t item,
106 const void *reserved, int idx)
108 const char *val = NULL;
119 case GPGME_ATTR_KEYID:
123 case GPGME_ATTR_OTRUST:
124 val = item->owner_trust;
127 case GPGME_ATTR_VALIDITY:
128 val = item->validity;
131 case GPGME_ATTR_USERID:
142 /* Return the value of the attribute WHAT of KEY, which has to be
143 representable by an integer. IDX specifies a running index if the
144 attribute appears more than once in the key. */
145 int gpgme_trust_item_get_int_attr (gpgme_trust_item_t item, _gpgme_attr_t what,
146 const void *reserved, int idx)
159 case GPGME_ATTR_LEVEL:
163 case GPGME_ATTR_TYPE: