gpgme/gpgme/recipient.c

167 lines
3.6 KiB
C
Raw Normal View History

2000-11-07 13:32:38 +00:00
/* recipient.c - mainatin recipient sets
* Copyright (C) 2000 Werner Koch (dd9jn)
2001-04-02 08:40:32 +00:00
* Copyright (C) 2001 g10 Code GmbH
2000-11-07 13:32:38 +00:00
*
* 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
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "util.h"
#include "context.h"
#include "rungpg.h"
GpgmeError
2000-11-13 13:25:22 +00:00
gpgme_recipients_new (GpgmeRecipients *r_rset)
2000-11-07 13:32:38 +00:00
{
2000-11-13 13:25:22 +00:00
GpgmeRecipients rset;
2000-11-07 13:32:38 +00:00
rset = xtrycalloc ( 1, sizeof *rset );
if (!rset)
return mk_error (Out_Of_Core);
*r_rset = rset;
return 0;
}
void
2000-11-13 13:25:22 +00:00
gpgme_recipients_release ( GpgmeRecipients rset )
2000-11-07 13:32:38 +00:00
{
/* fixme: release the linked list */
xfree ( rset );
}
GpgmeError
2000-11-13 13:25:22 +00:00
gpgme_recipients_add_name (GpgmeRecipients rset, const char *name )
2001-01-11 11:56:34 +00:00
{
return gpgme_recipients_add_name_with_validity (
rset, name, GPGME_VALIDITY_UNKNOWN
);
}
GpgmeError
gpgme_recipients_add_name_with_validity (GpgmeRecipients rset,
const char *name,
GpgmeValidity val )
2000-11-07 13:32:38 +00:00
{
2000-11-13 13:25:22 +00:00
struct user_id_s *r;
2000-11-07 13:32:38 +00:00
if (!name || !rset )
return mk_error (Invalid_Value);
r = xtrymalloc ( sizeof *r + strlen (name) );
if (!r)
return mk_error (Out_Of_Core);
2001-01-11 11:56:34 +00:00
r->validity = val;
r->name_part = "";
r->email_part = "";
r->comment_part = "";
2000-11-07 13:32:38 +00:00
strcpy (r->name, name );
r->next = rset->list;
rset->list = r;
return 0;
}
2001-01-11 11:56:34 +00:00
2000-11-07 13:32:38 +00:00
unsigned int
2000-11-13 13:25:22 +00:00
gpgme_recipients_count ( const GpgmeRecipients rset )
2000-11-07 13:32:38 +00:00
{
2000-11-13 13:25:22 +00:00
struct user_id_s *r;
2000-11-07 13:32:38 +00:00
unsigned int count = 0;
if ( rset ) {
for (r=rset->list ; r; r = r->next )
count++;
}
return count;
}
2000-12-14 14:45:35 +00:00
GpgmeError
gpgme_recipients_enum_open ( const GpgmeRecipients rset, void **ctx )
{
if (!rset || !ctx)
return mk_error (Invalid_Value);
*ctx = rset->list;
return 0;
}
const char *
gpgme_recipients_enum_read ( const GpgmeRecipients rset, void **ctx )
{
struct user_id_s *r;
if (!rset || !ctx)
return NULL; /* oops */
r = *ctx;
if ( r ) {
const char *s = r->name;
r = r->next;
*ctx = r;
return s;
}
return NULL;
}
GpgmeError
gpgme_recipients_enum_close ( const GpgmeRecipients rset, void **ctx )
{
if (!rset || !ctx)
return mk_error (Invalid_Value);
*ctx = NULL;
return 0;
}
2000-11-07 13:32:38 +00:00
void
_gpgme_append_gpg_args_from_recipients (
2000-11-13 13:25:22 +00:00
const GpgmeRecipients rset,
2000-11-07 13:32:38 +00:00
GpgObject gpg )
{
2000-11-13 13:25:22 +00:00
struct user_id_s *r;
2000-11-07 13:32:38 +00:00
assert (rset);
for (r=rset->list ; r; r = r->next ) {
_gpgme_gpg_add_arg ( gpg, "-r" );
_gpgme_gpg_add_arg ( gpg, r->name );
}
}
2001-01-11 11:56:34 +00:00
int
_gpgme_recipients_all_valid ( const GpgmeRecipients rset )
{
struct user_id_s *r;
2000-11-07 13:32:38 +00:00
2001-01-11 11:56:34 +00:00
assert (rset);
for (r=rset->list ; r; r = r->next ) {
if (r->validity != GPGME_VALIDITY_FULL
&& r->validity != GPGME_VALIDITY_ULTIMATE )
return 0; /*no*/
}
return 1; /*yes*/
}
2000-12-14 14:45:35 +00:00