From 9f622905cc70ac2c1e1732e4a6940179c9be0deb Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 30 Jan 2002 22:45:22 +0000 Subject: [PATCH] 2002-01-30 Marcus Brinkmann * gpgme.c (_gpgme_release_result): Call _gpgme_release_delete_result. * ops.h (_gpgme_release_delete_result): Add prototype. * types.h (DeleteResult): New type. * context.h (gpgme_context_s): Add DeleteResult to member result. * delete.c (enum delete_problem): New type. (struct delete_result_s): New structure. (_gpgme_release_delete_result): New function. (delete_status_handler): Implement more status codes. (gpgme_op_delete): Return error on failure. * import.c (MAX_IMPORTED_FIELDS): Bump up to 14. --- gpgme/ChangeLog | 18 +++++++++++- gpgme/context.h | 1 + gpgme/delete.c | 75 ++++++++++++++++++++++++++++++++++++++++++------- gpgme/gpgme.c | 1 + gpgme/import.c | 2 +- gpgme/ops.h | 3 ++ gpgme/types.h | 9 +++--- 7 files changed, 92 insertions(+), 17 deletions(-) diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 010c21e..8b47b09 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,19 @@ +2002-01-30 Marcus Brinkmann + + * gpgme.c (_gpgme_release_result): Call + _gpgme_release_delete_result. + * ops.h (_gpgme_release_delete_result): Add prototype. + * types.h (DeleteResult): New type. + * context.h (gpgme_context_s): Add DeleteResult to member result. + + * delete.c (enum delete_problem): New type. + (struct delete_result_s): New structure. + (_gpgme_release_delete_result): New function. + (delete_status_handler): Implement more status codes. + (gpgme_op_delete): Return error on failure. + + * import.c (MAX_IMPORTED_FIELDS): Bump up to 14. + 2002-01-30 Marcus Brinkmann * import.c (struct import_result_s): New structure. @@ -6,7 +22,7 @@ (import_status_handler): Implement. * gpgme.c (_gpgme_release_result): Add call to _gpgme_release_import_result. - * ops.h (_gpgme_release_impoer_result): Add prototype. + * ops.h (_gpgme_release_import_result): Add prototype. * types.h (ImportResult): New type. * context.h (gpgme_context_s): Add ImportResult to member result. diff --git a/gpgme/context.h b/gpgme/context.h index 02d3954..ae2460b 100644 --- a/gpgme/context.h +++ b/gpgme/context.h @@ -69,6 +69,7 @@ struct gpgme_context_s { EncryptResult encrypt; PassphraseResult passphrase; ImportResult import; + DeleteResult delete; } result; GpgmeData notation; /* last signature notation */ diff --git a/gpgme/delete.c b/gpgme/delete.c index a5f122f..23044c4 100644 --- a/gpgme/delete.c +++ b/gpgme/delete.c @@ -30,19 +30,58 @@ #include "ops.h" #include "key.h" + +enum delete_problem + { + DELETE_No_Problem = 0, + DELETE_No_Such_Key = 1, + DELETE_Must_Delete_Secret_Key = 2 + }; + + +struct delete_result_s +{ + enum delete_problem problem; +}; + + +void +_gpgme_release_delete_result (DeleteResult result) +{ + if (!result) + return; + xfree (result); +} + + static void -delete_status_handler ( GpgmeCtx ctx, GpgStatusCode code, char *args ) +delete_status_handler (GpgmeCtx ctx, GpgStatusCode code, char *args) { - if ( ctx->out_of_core ) - return; + if (ctx->out_of_core) + return; + + if (!ctx->result.delete) + { + ctx->result.delete = xtrycalloc (1, sizeof *ctx->result.delete); + if (!ctx->result.delete) + { + ctx->out_of_core = 1; + return; + } + } + + switch (code) + { + case STATUS_EOF: + break; - switch (code) { - case STATUS_EOF: - break; + case STATUS_DELETE_PROBLEM: + ctx->result.delete->problem = atoi (args); + break; - default: - /* ignore all other codes */ - break; + default: + /* Ignore all other codes. */ + break; } } @@ -108,7 +147,23 @@ gpgme_op_delete (GpgmeCtx ctx, const GpgmeKey key, int allow_secret) if (!err) { gpgme_wait (ctx, 1); - /* FIXME: check for success */ + if (ctx->result.delete) + { + switch (ctx->result.delete->problem) + { + case DELETE_No_Problem: + break; + case DELETE_No_Such_Key: + err = mk_error(Invalid_Key); + break; + case DELETE_Must_Delete_Secret_Key: + err = mk_error(Conflict); + break; + default: + err = mk_error(General_Error); + break; + } + } } return err; } diff --git a/gpgme/gpgme.c b/gpgme/gpgme.c index 25e6b61..d528f8f 100644 --- a/gpgme/gpgme.c +++ b/gpgme/gpgme.c @@ -87,6 +87,7 @@ _gpgme_release_result (GpgmeCtx ctx) _gpgme_release_encrypt_result (ctx->result.encrypt); _gpgme_release_passphrase_result (ctx->result.passphrase); _gpgme_release_import_result (ctx->result.import); + _gpgme_release_delete_result (ctx->result.delete); memset (&ctx->result, 0, sizeof (ctx->result)); _gpgme_set_op_info (ctx, NULL); } diff --git a/gpgme/import.c b/gpgme/import.c index 8199057..f038091 100644 --- a/gpgme/import.c +++ b/gpgme/import.c @@ -52,7 +52,7 @@ _gpgme_release_import_result (ImportResult result) static void append_xml_impinfo (GpgmeData *rdh, GpgStatusCode code, char *args) { -#define MAX_IMPORTED_FIELDS 13 +#define MAX_IMPORTED_FIELDS 14 static char *imported_fields[MAX_IMPORTED_FIELDS] = { "keyid", "username", 0 }; static char *import_res_fields[MAX_IMPORTED_FIELDS] diff --git a/gpgme/ops.h b/gpgme/ops.h index dcdeba7..ed6e5db 100644 --- a/gpgme/ops.h +++ b/gpgme/ops.h @@ -98,6 +98,9 @@ GpgmeError _gpgme_passphrase_result (GpgmeCtx ctx); /*-- import.c --*/ void _gpgme_release_import_result (ImportResult res); +/*-- delete.c --*/ +void _gpgme_release_delete_result (DeleteResult res); + /*-- version.c --*/ const char *_gpgme_compare_versions (const char *my_version, const char *req_version); diff --git a/gpgme/types.h b/gpgme/types.h index 71dab9a..38f58f9 100644 --- a/gpgme/types.h +++ b/gpgme/types.h @@ -80,10 +80,9 @@ typedef struct passphrase_result_s *PassphraseResult; struct import_result_s; typedef struct import_result_s *ImportResult; - -#endif /* TYPES_H */ - - - +/*-- delete.c --*/ +struct delete_result_s; +typedef struct delete_result_s *DeleteResult; +#endif /* TYPES_H */ -- 2.26.2