1 /* recipient.c - mainatin recipient sets
2 * Copyright (C) 2000 Werner Koch (dd9jn)
3 * Copyright (C) 2001 g10 Code GmbH
5 * This file is part of GPGME.
7 * GPGME is free software; you can redistribute it and/or modify
8 * it 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,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
33 * gpgme_recipients_new:
34 * @r_rset: Returns the new object.
36 * Create a new uninitialized Reciepient set Object.
38 * Return value: 0 on success or an error code.
41 gpgme_recipients_new (GpgmeRecipients *r_rset)
45 rset = xtrycalloc ( 1, sizeof *rset );
47 return mk_error (Out_Of_Core);
53 * gpgme_recipients_release:
54 * @rset: Recipient Set object
56 * Free the given object.
59 gpgme_recipients_release ( GpgmeRecipients rset )
62 struct user_id_s *u, *u2;
64 for (u = rset->list; u; u = u2) {
74 * gpgme_recipients_add_name:
75 * @rset: Recipient Set object
76 * @name: user name or keyID
78 * Add a name to the recipient Set.
80 * Return value: 0 on success or an error code
83 gpgme_recipients_add_name (GpgmeRecipients rset, const char *name )
85 return gpgme_recipients_add_name_with_validity (
86 rset, name, GPGME_VALIDITY_UNKNOWN
91 * gpgme_recipients_add_name_with_validity:
92 * @rset: Recipient Set object
93 * @name: user name or keyID
94 * @val: Validity value
96 * Same as gpgme_recipients_add_name() but with explictly given key
97 * validity. Use one of the constants
98 * %GPGME_VALIDITY_UNKNOWN, %GPGME_VALIDITY_UNDEFINED,
99 * %GPGME_VALIDITY_NEVER, %GPGME_VALIDITY_MARGINAL,
100 * %GPGME_VALIDITY_FULL, %GPGME_VALIDITY_ULTIMATE5
101 * for the validity. %GPGME_VALIDITY_UNKNOWN is implicitly used by
102 * gpgme_recipients_add_name().
104 * Return value: o on success or an error value.
107 gpgme_recipients_add_name_with_validity (GpgmeRecipients rset,
114 return mk_error (Invalid_Value);
115 r = xtrymalloc ( sizeof *r + strlen (name) );
117 return mk_error (Out_Of_Core);
121 r->comment_part = "";
122 strcpy (r->name, name );
123 r->next = rset->list;
131 * gpgme_recipients_count:
132 * @rset: Recipient Set object
134 * Return value: The number of recipients in the set.
137 gpgme_recipients_count ( const GpgmeRecipients rset )
140 unsigned int count = 0;
143 for (r=rset->list ; r; r = r->next )
152 * gpgme_recipients_enum_open:
153 * @rset: Recipient Set object
156 * Start an enumeration on the Recipient Set object. The caller must pass
157 * the address of a void pointer which is used as the enumerator object.
159 * Return value: 0 on success or an error code.
161 * See also: gpgme_recipients_enum_read(), gpgme_recipients_enum_close().
164 gpgme_recipients_enum_open ( const GpgmeRecipients rset, void **ctx )
167 return mk_error (Invalid_Value);
174 * gpgme_recipients_enum_read:
175 * @rset: Recipient Set object
178 * Return the name of the next user name from the given recipient
179 * set. This name is valid as along as the @rset is valid and until
180 * the next call to this function.
182 * Return value: name or NULL for no more names.
184 * See also: gpgme_recipients_enum_read(), gpgme_recipients_enum_close().
187 gpgme_recipients_enum_read ( const GpgmeRecipients rset, void **ctx )
192 return NULL; /* oops */
196 const char *s = r->name;
206 * gpgme_recipients_enum_close:
207 * @rset: Recipient Set object
210 * Release the enumerator @rset for this object.
212 * Return value: 0 on success or %GPGME_Invalid_Value;
214 * See also: gpgme_recipients_enum_read(), gpgme_recipients_enum_close().
217 gpgme_recipients_enum_close ( const GpgmeRecipients rset, void **ctx )
220 return mk_error (Invalid_Value);
226 _gpgme_recipients_all_valid ( const GpgmeRecipients rset )
231 for (r=rset->list ; r; r = r->next ) {
232 if (r->validity != GPGME_VALIDITY_FULL
233 && r->validity != GPGME_VALIDITY_ULTIMATE )