2ffb03a969
2003-04-27 Marcus Brinkmann <marcus@g10code.de> * gpgme.texi (Deleting Keys): Document GPGME_Ambiguous_Specification. (Error Values): Remove GPGME_Invalid_Type and GPGME_Invalid_Mode. Add GPGME_Unknown_Reason, GPGME_Not_Found, GPGME_Ambiguous_Specification, GPGME_Wrong_Key_Usage, GPGME_Key_Revoked, GPGME_Key_Expired, GPGME_No_CRL_Known, GPGME_CRL_Too_Old, GPGME_Policy_Mismatch, GPGME_No_Secret_Key, GPGME_Key_Not_Trusted, GPGME_Issuer_Missing, GPGME_Chain_Too_Long, GPGME_Unsupported_Algorithm, GPGME_Sig_Expired, GPGME_Bad_Signature, GPGME_No_Public_Key. gpgme/ 2003-04-27 Marcus Brinkmann <marcus@g10code.de> * delete.c: Include <errno.h> and "gpgme.h", but not "util.h" or "key.h". (enum delete_problem): Move into function delete_status_handler. (delete_status_handler): Change first argument to void *. Parse delete problem with strtol instead atoi. Return better error values. (_gpgme_op_delete_start): Rename to ... (delete_start): ... this. Rework error handling. (gpgme_op_delete_start): Use delete_start instead _gpgme_op_delete_start. (gpgme_op_delete): Likewise. * gpgme.h (GpgmeDataType): Removed.
108 lines
2.6 KiB
C
108 lines
2.6 KiB
C
/* delete.c - Delete a key.
|
||
Copyright (C) 2001, 2002, 2003 g10 Code GmbH
|
||
|
||
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 GPGME; if not, write to the Free Software Foundation,
|
||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||
|
||
#if HAVE_CONFIG_H
|
||
#include <config.h>
|
||
#endif
|
||
#include <stdlib.h>
|
||
#include <errno.h>
|
||
|
||
#include "gpgme.h"
|
||
#include "context.h"
|
||
#include "ops.h"
|
||
|
||
|
||
static GpgmeError
|
||
delete_status_handler (void *priv, GpgmeStatusCode code, char *args)
|
||
{
|
||
if (code == GPGME_STATUS_DELETE_PROBLEM)
|
||
{
|
||
enum delete_problem
|
||
{
|
||
DELETE_No_Problem = 0,
|
||
DELETE_No_Such_Key = 1,
|
||
DELETE_Must_Delete_Secret_Key = 2,
|
||
DELETE_Ambiguous_Specification = 3
|
||
};
|
||
long problem;
|
||
char *tail;
|
||
|
||
errno = 0;
|
||
problem = strtol (args, &tail, 0);
|
||
if (errno || (*tail && *tail != ' '))
|
||
return GPGME_General_Error;
|
||
|
||
switch (problem)
|
||
{
|
||
case DELETE_No_Problem:
|
||
break;
|
||
|
||
case DELETE_No_Such_Key:
|
||
return GPGME_Invalid_Key;
|
||
|
||
case DELETE_Must_Delete_Secret_Key:
|
||
return GPGME_Conflict;
|
||
|
||
case DELETE_Ambiguous_Specification:
|
||
return GPGME_Ambiguous_Specification;
|
||
|
||
default:
|
||
return GPGME_General_Error;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|
||
static GpgmeError
|
||
delete_start (GpgmeCtx ctx, int synchronous, const GpgmeKey key,
|
||
int allow_secret)
|
||
{
|
||
GpgmeError err;
|
||
|
||
err = _gpgme_op_reset (ctx, synchronous);
|
||
if (err)
|
||
return err;
|
||
|
||
_gpgme_engine_set_status_handler (ctx->engine, delete_status_handler, ctx);
|
||
|
||
return _gpgme_engine_op_delete (ctx->engine, key, allow_secret);
|
||
}
|
||
|
||
|
||
/* Delete KEY from the keyring. If ALLOW_SECRET is non-zero, secret
|
||
keys are also deleted. */
|
||
GpgmeError
|
||
gpgme_op_delete_start (GpgmeCtx ctx, const GpgmeKey key, int allow_secret)
|
||
{
|
||
return delete_start (ctx, 0, key, allow_secret);
|
||
}
|
||
|
||
|
||
/* Delete KEY from the keyring. If ALLOW_SECRET is non-zero, secret
|
||
keys are also deleted. */
|
||
GpgmeError
|
||
gpgme_op_delete (GpgmeCtx ctx, const GpgmeKey key, int allow_secret)
|
||
{
|
||
GpgmeError err = delete_start (ctx, 1, key, allow_secret);
|
||
if (!err)
|
||
err = _gpgme_wait_one (ctx);
|
||
return err;
|
||
}
|