~ubuntu-branches/ubuntu/lucid/gpgme1.0/lucid

« back to all changes in this revision

Viewing changes to gpgme/trust-item.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman, Bhavani Shankar, Scott Kitterman
  • Date: 2008-12-31 02:39:33 UTC
  • mfrom: (1.1.6 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081231023933-zi5r2w9vf7fdz0x9
Tags: 1.1.8-1ubuntu1
[ Bhavani Shankar ]
* Merge from debian unstable, remaining changes: LP: #311666
  - debian/rules: enable tests

[ Scott Kitterman ]
* Re-enable testsuite on armel since it's no longer a first build 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* trust-item.c - Trust item objects.
2
 
   Copyright (C) 2000 Werner Koch (dd9jn)
3
 
   Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
4
 
 
5
 
   This file is part of GPGME.
6
 
 
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.
11
 
   
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.
16
 
   
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
20
 
   02111-1307, USA.  */
21
 
 
22
 
#if HAVE_CONFIG_H
23
 
#include <config.h>
24
 
#endif
25
 
#include <stdlib.h>
26
 
#include <string.h>
27
 
#include <assert.h>
28
 
#include <errno.h>
29
 
 
30
 
#include "util.h"
31
 
#include "ops.h"
32
 
#include "sema.h"
33
 
 
34
 
 
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);
39
 
 
40
 
 
41
 
/* Create a new trust item.  */
42
 
gpgme_error_t
43
 
_gpgme_trust_item_new (gpgme_trust_item_t *r_item)
44
 
{
45
 
  gpgme_trust_item_t item;
46
 
 
47
 
  item = calloc (1, sizeof *item);
48
 
  if (!item)
49
 
    return gpg_error_from_errno (errno);
50
 
  item->_refs = 1;
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';
57
 
  *r_item = item;
58
 
  return 0;
59
 
}
60
 
 
61
 
 
62
 
/* Acquire a reference to ITEM.  */
63
 
void
64
 
gpgme_trust_item_ref (gpgme_trust_item_t item)
65
 
{
66
 
  LOCK (trust_item_ref_lock);
67
 
  item->_refs++;
68
 
  UNLOCK (trust_item_ref_lock);
69
 
}
70
 
 
71
 
 
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.  */
77
 
void
78
 
gpgme_trust_item_unref (gpgme_trust_item_t item)
79
 
{
80
 
  LOCK (trust_item_ref_lock);
81
 
  assert (item->_refs > 0);
82
 
  if (--item->_refs)
83
 
    {
84
 
      UNLOCK (trust_item_ref_lock);
85
 
      return;
86
 
    }
87
 
  UNLOCK (trust_item_ref_lock);
88
 
 
89
 
  if (item->name)
90
 
    free (item->name);
91
 
  free (item);
92
 
}
93
 
 
94
 
 
95
 
/* Compatibility interfaces.  */
96
 
void
97
 
gpgme_trust_item_release (gpgme_trust_item_t item)
98
 
{
99
 
  gpgme_trust_item_unref (item);
100
 
}
101
 
 
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,
105
 
                                              _gpgme_attr_t what,
106
 
                                              const void *reserved, int idx)
107
 
{
108
 
  const char *val = NULL;
109
 
 
110
 
  if (!item)
111
 
    return NULL;
112
 
  if (reserved)
113
 
    return NULL;
114
 
  if (idx)
115
 
    return NULL;
116
 
 
117
 
  switch (what)
118
 
    {
119
 
    case GPGME_ATTR_KEYID:
120
 
      val = item->keyid;
121
 
      break;
122
 
 
123
 
    case GPGME_ATTR_OTRUST:  
124
 
      val = item->owner_trust;
125
 
      break;
126
 
 
127
 
    case GPGME_ATTR_VALIDITY:
128
 
      val = item->validity;
129
 
      break;
130
 
 
131
 
    case GPGME_ATTR_USERID:  
132
 
      val = item->name;
133
 
      break;
134
 
 
135
 
    default:
136
 
      break;
137
 
    }
138
 
  return val;
139
 
}
140
 
 
141
 
 
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)
147
 
{
148
 
  int val = 0;
149
 
 
150
 
  if (!item)
151
 
    return 0;
152
 
  if (reserved)
153
 
    return 0;
154
 
  if (idx)
155
 
    return 0;
156
 
 
157
 
  switch (what)
158
 
    {
159
 
    case GPGME_ATTR_LEVEL:    
160
 
      val = item->level;
161
 
      break;
162
 
 
163
 
    case GPGME_ATTR_TYPE:    
164
 
      val = item->type;
165
 
      break;
166
 
 
167
 
    default:
168
 
      break;
169
 
    }
170
 
  return val;
171
 
}