From b083ea8da3619399b9c33887257d3c220941a704 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Sun, 19 Jan 2003 21:51:07 +0000 Subject: [PATCH] 2003-01-19 Marcus Brinkmann * rungpg.c (_gpgme_engine_ops_gpg): Remove gpg_start. (gpg_start): Rename to ... (start): ... this function. Change arguments to GpgObject. (gpg_decrypt): Call start. (gpg_edit): Likewise. (gpg_encrypt): Likewise. (gpg_encrypt_sign): Likewise. (gpg_export): Likewise. (gpg_import): Likewise. (gpg_keylist): Likewise. (gpg_keylist_ext): Likewise. (gpg_trustlist): Likewise. (gpg_verify): Likewise. * engine-gpgsm.c (_gpgme_engine_ops_encrypt): Remove gpgsm_start. (gpgsm_start): Rename to ... (struct gpgsm_object_s): Remove member command. (gpgsm_release): Don't free command. (start): ... this function. Change arguments to GpgsmObject and const char *. (gpgsm_decrypt): Call start. (gpgsm_delete): Likewise. (gpgsm_encrypt): Likewise. (gpgsm_export): Likewise. (gpgsm_genkey): Likewise. (gpgsm_import): Likewise. (gpgsm_keylist): Likewise. (gpgsm_keylist_ext): Likewise. (gpgsm_verify): Likewise. * decrypt.c (_gpgme_decrypt_start): Don't call _gpgme_engine_start. * delete.c (_gpgme_op_delete_start): Likewise. * edit.c (_gpgme_op_edit_start): Likewise. * encrypt.c (_gpgme_op_encrypt_start): * encrypt-sign.c (_gpgme_op_encrypt_sign_start): * export.c (_gpgme_op_export_start): Likewise. * genkey.c (_gpgme_op_genkey_start): Likewise. * import.c (_gpgme_op_import_start): Likewise. * keylist.c (gpgme_op_keylist_ext_start): Likewise. (gpgme_op_keylist_start): Likewise. * sign.c (_gpgme_op_sign_start): Likewise. * trustlist.c (gpgme_op_trustlist_start): Likewise. * verify.c (_gpgme_op_verify_start): Likewise. * engine-backend.h (struct engine_ops): Remove member start. * engine.h (_gpgme_engine_start): Remove prototype. * engine.c (_gpgme_engine_start): Remove function. --- gpgme/ChangeLog | 52 ++ gpgme/decrypt.c | 3 - gpgme/delete.c | 39 +- gpgme/edit.c | 42 +- gpgme/encrypt-sign.c | 42 +- gpgme/encrypt.c | 43 +- gpgme/engine-backend.h | 1 - gpgme/engine-gpgsm.c | 1180 ++++++++++++++++++++-------------------- gpgme/engine.c | 13 - gpgme/engine.h | 1 - gpgme/export.c | 41 +- gpgme/genkey.c | 3 - gpgme/import.c | 44 +- gpgme/key.c | 2 + gpgme/keylist.c | 7 - gpgme/rungpg.c | 43 +- gpgme/sign.c | 54 +- gpgme/trustlist.c | 66 ++- gpgme/verify.c | 2 - 19 files changed, 848 insertions(+), 830 deletions(-) diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 040c4588..1aec903b 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,55 @@ +2003-01-19 Marcus Brinkmann + + * rungpg.c (_gpgme_engine_ops_gpg): Remove gpg_start. + (gpg_start): Rename to ... + (start): ... this function. Change arguments to GpgObject. + (gpg_decrypt): Call start. + (gpg_edit): Likewise. + (gpg_encrypt): Likewise. + (gpg_encrypt_sign): Likewise. + (gpg_export): Likewise. + (gpg_import): Likewise. + (gpg_keylist): Likewise. + (gpg_keylist_ext): Likewise. + (gpg_trustlist): Likewise. + (gpg_verify): Likewise. + + * engine-gpgsm.c (_gpgme_engine_ops_encrypt): Remove gpgsm_start. + (gpgsm_start): Rename to ... + (struct gpgsm_object_s): Remove member command. + (gpgsm_release): Don't free command. + (start): ... this function. Change arguments to GpgsmObject and + const char *. + (gpgsm_decrypt): Call start. + (gpgsm_delete): Likewise. + (gpgsm_encrypt): Likewise. + (gpgsm_export): Likewise. + (gpgsm_genkey): Likewise. + (gpgsm_import): Likewise. + (gpgsm_keylist): Likewise. + (gpgsm_keylist_ext): Likewise. + (gpgsm_verify): Likewise. + + * decrypt.c (_gpgme_decrypt_start): Don't call + _gpgme_engine_start. + * delete.c (_gpgme_op_delete_start): Likewise. + * edit.c (_gpgme_op_edit_start): Likewise. + * encrypt.c (_gpgme_op_encrypt_start): + * encrypt-sign.c (_gpgme_op_encrypt_sign_start): + * export.c (_gpgme_op_export_start): Likewise. + * genkey.c (_gpgme_op_genkey_start): Likewise. + * import.c (_gpgme_op_import_start): Likewise. + * keylist.c (gpgme_op_keylist_ext_start): Likewise. + (gpgme_op_keylist_start): Likewise. + * sign.c (_gpgme_op_sign_start): Likewise. + * trustlist.c (gpgme_op_trustlist_start): Likewise. + * verify.c (_gpgme_op_verify_start): Likewise. + + * engine-backend.h (struct engine_ops): Remove member start. + + * engine.h (_gpgme_engine_start): Remove prototype. + * engine.c (_gpgme_engine_start): Remove function. + 2003-01-06 Werner Koch * keylist.c (set_mainkey_capability): Handle 'd' and 'D' used diff --git a/gpgme/decrypt.c b/gpgme/decrypt.c index 96fbc211..7438b374 100644 --- a/gpgme/decrypt.c +++ b/gpgme/decrypt.c @@ -192,9 +192,6 @@ _gpgme_decrypt_start (GpgmeCtx ctx, int synchronous, err = _gpgme_engine_op_decrypt (ctx->engine, ciph, plain); - if (!err) /* And kick off the process. */ - err = _gpgme_engine_start (ctx->engine, ctx); - leave: if (err) { diff --git a/gpgme/delete.c b/gpgme/delete.c index 33b83e19..a3ed47c5 100644 --- a/gpgme/delete.c +++ b/gpgme/delete.c @@ -1,24 +1,25 @@ /* delete.c - delete a key - * Copyright (C) 2001, 2002 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ + Copyright (C) 2001, 2002 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 +#endif #include #include #include @@ -108,8 +109,6 @@ _gpgme_op_delete_start (GpgmeCtx ctx, int synchronous, _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); err = _gpgme_engine_op_delete (ctx->engine, key, allow_secret); - if (!err) - err = _gpgme_engine_start (ctx->engine, ctx); leave: if (err) diff --git a/gpgme/edit.c b/gpgme/edit.c index 2c74b98f..a12486c6 100644 --- a/gpgme/edit.c +++ b/gpgme/edit.c @@ -1,24 +1,25 @@ /* edit.c - key edit functions - * Copyright (C) 2002 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ + Copyright (C) 2002 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 +#endif #include #include #include @@ -110,11 +111,8 @@ _gpgme_op_edit_start (GpgmeCtx ctx, int synchronous, _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); - _gpgme_engine_op_edit (ctx->engine, key, out, ctx); + err = _gpgme_engine_op_edit (ctx->engine, key, out, ctx); - /* And kick off the process. */ - err = _gpgme_engine_start (ctx->engine, ctx); - leave: if (err) { diff --git a/gpgme/encrypt-sign.c b/gpgme/encrypt-sign.c index 43bd1dc7..2ce43f05 100644 --- a/gpgme/encrypt-sign.c +++ b/gpgme/encrypt-sign.c @@ -1,25 +1,24 @@ /* encrypt-sign.c - encrypt and verify functions - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002 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. */ -#ifdef HAVE_CONFIG_H +#if HAVE_CONFIG_H #include #endif #include @@ -75,9 +74,6 @@ _gpgme_op_encrypt_sign_start (GpgmeCtx ctx, int synchronous, err = _gpgme_engine_op_encrypt_sign (ctx->engine, recp, plain, cipher, ctx->use_armor, ctx /* FIXME */); - if (!err) /* And kick off the process. */ - err = _gpgme_engine_start (ctx->engine, ctx); - leave: if (err) { diff --git a/gpgme/encrypt.c b/gpgme/encrypt.c index 8ed02026..03131fa4 100644 --- a/gpgme/encrypt.c +++ b/gpgme/encrypt.c @@ -1,25 +1,26 @@ /* encrypt.c - encrypt functions - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002 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 +#endif #include #include #include @@ -203,10 +204,6 @@ _gpgme_op_encrypt_start (GpgmeCtx ctx, int synchronous, err = _gpgme_engine_op_encrypt (ctx->engine, recp, plain, ciph, ctx->use_armor); - - if (!err) /* And kick off the process. */ - err = _gpgme_engine_start (ctx->engine, ctx); - leave: if (err) { diff --git a/gpgme/engine-backend.h b/gpgme/engine-backend.h index 70c2c03e..4d4b800d 100644 --- a/gpgme/engine-backend.h +++ b/gpgme/engine-backend.h @@ -72,7 +72,6 @@ struct engine_ops GpgmeError (*trustlist) (void *engine, const char *pattern); GpgmeError (*verify) (void *engine, GpgmeData sig, GpgmeData signed_text, GpgmeData plaintext); - GpgmeError (*start) (void *engine, void *opaque); void (*set_io_cbs) (void *engine, struct GpgmeIOCbs *io_cbs); void (*io_event) (void *engine, GpgmeEventIO type, void *type_data); diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c index 545d26ad..6b29de7e 100644 --- a/gpgme/engine-gpgsm.c +++ b/gpgme/engine-gpgsm.c @@ -75,8 +75,6 @@ struct gpgsm_object_s iocb_data_t message_cb; int message_fd_server; - char *command; - struct { GpgmeStatusHandler fnc; @@ -294,7 +292,6 @@ gpgsm_release (void *engine) assuan_disconnect (gpgsm->assuan_ctx); free (gpgsm->colon.attic.line); - free (gpgsm->command); free (gpgsm); } @@ -659,560 +656,6 @@ map_input_enc (GpgmeData d) } -static GpgmeError -gpgsm_decrypt (void *engine, GpgmeData ciph, GpgmeData plain) -{ - GpgsmObject gpgsm = engine; - GpgmeError err; - - if (!gpgsm) - return mk_error (Invalid_Value); - - gpgsm->command = strdup ("DECRYPT"); - if (!gpgsm->command) - return mk_error (Out_Of_Core); - - gpgsm->input_cb.data = ciph; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, - map_input_enc (gpgsm->input_cb.data)); - if (err) - return mk_error (General_Error); /* FIXME */ - gpgsm->output_cb.data = plain; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, 0); - if (err) - return mk_error (General_Error); /* FIXME */ - _gpgme_io_close (gpgsm->message_cb.fd); - - return 0; -} - - -static GpgmeError -gpgsm_delete (void *engine, GpgmeKey key, int allow_secret) -{ - GpgsmObject gpgsm = engine; - char *fpr = (char *) gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, 0); - char *linep = fpr; - char *line; - int length = 8; /* "DELKEYS " */ - - if (!fpr) - return mk_error (Invalid_Key); - - while (*linep) - { - length++; - if (*linep == '%' || *linep == ' ' || *linep == '+') - length += 2; - linep++; - } - length++; - - line = malloc (length); - if (!line) - return mk_error (Out_Of_Core); - - strcpy (line, "DELKEYS "); - linep = &line[8]; - - while (*fpr) - { - switch (*fpr) - { - case '%': - *(linep++) = '%'; - *(linep++) = '2'; - *(linep++) = '5'; - break; - case ' ': - *(linep++) = '%'; - *(linep++) = '2'; - *(linep++) = '0'; - break; - case '+': - *(linep++) = '%'; - *(linep++) = '2'; - *(linep++) = 'B'; - break; - default: - *(linep++) = *fpr; - break; - } - fpr++; - } - *linep = '\0'; - - gpgsm->command = line; - _gpgme_io_close (gpgsm->output_cb.fd); - _gpgme_io_close (gpgsm->input_cb.fd); - _gpgme_io_close (gpgsm->message_cb.fd); - - return 0; -} - - -static GpgmeError -set_recipients (GpgsmObject gpgsm, GpgmeRecipients recp) -{ - GpgmeError err; - ASSUAN_CONTEXT ctx = gpgsm->assuan_ctx; - char *line; - int linelen; - struct user_id_s *r; - int valid_recipients = 0; - - linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */ - line = malloc (10 + 40 + 1); - if (!line) - return mk_error (Out_Of_Core); - strcpy (line, "RECIPIENT "); - for (r = recp->list; r; r = r->next) - { - int newlen = 11 + strlen (r->name); - if (linelen < newlen) - { - char *newline = realloc (line, newlen); - if (! newline) - { - free (line); - return mk_error (Out_Of_Core); - } - line = newline; - linelen = newlen; - } - strcpy (&line[10], r->name); - - err = gpgsm_assuan_simple_command (ctx, line, gpgsm->status.fnc, - gpgsm->status.fnc_value); - if (!err) - valid_recipients = 1; - else if (err != GPGME_Invalid_Key) - { - free (line); - return err; - } - } - free (line); - if (!valid_recipients && gpgsm->status.fnc) - gpgsm->status.fnc (gpgsm->status.fnc_value, GPGME_STATUS_NO_RECP, ""); - return 0; -} - - -static GpgmeError -gpgsm_encrypt (void *engine, GpgmeRecipients recp, GpgmeData plain, - GpgmeData ciph, int use_armor) -{ - GpgsmObject gpgsm = engine; - GpgmeError err; - - if (!gpgsm) - return mk_error (Invalid_Value); - if (!recp) - return mk_error (Not_Implemented); - - gpgsm->command = strdup ("ENCRYPT"); - if (!gpgsm->command) - return mk_error (Out_Of_Core); - - gpgsm->input_cb.data = plain; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, - map_input_enc (gpgsm->input_cb.data)); - if (err) - return err; - gpgsm->output_cb.data = ciph; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, - use_armor ? "--armor" : 0); - if (err) - return err; - _gpgme_io_close (gpgsm->message_cb.fd); - - err = set_recipients (gpgsm, recp); - if (err) - return err; - - return 0; -} - - -static GpgmeError -gpgsm_export (void *engine, GpgmeRecipients recp, GpgmeData keydata, - int use_armor) -{ - GpgsmObject gpgsm = engine; - GpgmeError err = 0; - char *cmd = NULL; - int cmdi; - int cmdlen = 32; - - if (!gpgsm) - return mk_error (Invalid_Value); - - cmd = malloc (cmdlen); - if (!cmd) - return mk_error (Out_Of_Core); - strcpy (cmd, "EXPORT"); - cmdi = 6; - - if (recp) - { - void *ec; - const char *s; - - err = gpgme_recipients_enum_open (recp, &ec); - while (!err && (s = gpgme_recipients_enum_read (recp, &ec))) - { - int slen = strlen (s); - /* New string is old string + ' ' + s + '\0'. */ - if (cmdlen < cmdi + 1 + slen + 1) - { - char *newcmd = realloc (cmd, cmdlen * 2); - if (!newcmd) - { - free (cmd); - return mk_error (Out_Of_Core); - } - cmd = newcmd; - cmdlen *= 2; - } - cmd[cmdi++] = ' '; - strcpy (cmd + cmdi, s); - cmdi += slen; - } - if (!err) - err = gpgme_recipients_enum_close (recp, &ec); - if (err) - return err; - } - - gpgsm->command = cmd; - - gpgsm->output_cb.data = keydata; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, - use_armor ? "--armor" : 0); - if (err) - return err; - _gpgme_io_close (gpgsm->input_cb.fd); - _gpgme_io_close (gpgsm->message_cb.fd); - - return 0; -} - - -static GpgmeError -gpgsm_genkey (void *engine, GpgmeData help_data, int use_armor, - GpgmeData pubkey, GpgmeData seckey) -{ - GpgsmObject gpgsm = engine; - GpgmeError err; - - if (!gpgsm || !pubkey || seckey) - return mk_error (Invalid_Value); - - gpgsm->command = strdup ("GENKEY"); - if (!gpgsm->command) - return mk_error (Out_Of_Core); - - gpgsm->input_cb.data = help_data; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, - map_input_enc (gpgsm->input_cb.data)); - if (err) - return err; - gpgsm->output_cb.data = pubkey; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, - use_armor ? "--armor" : 0); - if (err) - return err; - _gpgme_io_close (gpgsm->message_cb.fd); - - return 0; -} - - -static GpgmeError -gpgsm_import (void *engine, GpgmeData keydata) -{ - GpgsmObject gpgsm = engine; - GpgmeError err; - - if (!gpgsm) - return mk_error (Invalid_Value); - - gpgsm->command = strdup ("IMPORT"); - if (!gpgsm->command) - return mk_error (Out_Of_Core); - - gpgsm->input_cb.data = keydata; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, - map_input_enc (gpgsm->input_cb.data)); - if (err) - return err; - _gpgme_io_close (gpgsm->output_cb.fd); - _gpgme_io_close (gpgsm->message_cb.fd); - - return 0; -} - - -static GpgmeError -gpgsm_keylist (void *engine, const char *pattern, int secret_only, - int keylist_mode) -{ - GpgsmObject gpgsm = engine; - char *line; - GpgmeError err; - - if (!pattern) - pattern = ""; - - if (asprintf (&line, "OPTION list-mode=%d", (keylist_mode & 3)) < 0) - return mk_error (Out_Of_Core); - err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); - free (line); - if (err) - return err; - - /* Length is "LISTSECRETKEYS " + p + '\0'. */ - line = malloc (15 + strlen (pattern) + 1); - if (!line) - return mk_error (Out_Of_Core); - if (secret_only) - { - strcpy (line, "LISTSECRETKEYS "); - strcpy (&line[15], pattern); - } - else - { - strcpy (line, "LISTKEYS "); - strcpy (&line[9], pattern); - } - - _gpgme_io_close (gpgsm->input_cb.fd); - _gpgme_io_close (gpgsm->output_cb.fd); - _gpgme_io_close (gpgsm->message_cb.fd); - - gpgsm->command = line; - return 0; -} - - -static GpgmeError -gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only, - int reserved, int keylist_mode) -{ - GpgsmObject gpgsm = engine; - char *line; - GpgmeError err; - /* Length is "LISTSECRETKEYS " + p + '\0'. */ - int length = 15 + 1; - char *linep; - - if (reserved) - return mk_error (Invalid_Value); - - if (asprintf (&line, "OPTION list-mode=%d", (keylist_mode & 3)) < 0) - return mk_error (Out_Of_Core); - err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); - free (line); - if (err) - return err; - - if (pattern && *pattern) - { - const char **pat = pattern; - - while (*pat) - { - const char *patlet = *pat; - - while (*patlet) - { - length++; - if (*patlet == '%' || *patlet == ' ' || *patlet == '+') - length += 2; - patlet++; - } - pat++; - /* This will allocate one byte more than necessary. */ - length++; - } - } - line = malloc (length); - if (!line) - return mk_error (Out_Of_Core); - if (secret_only) - { - strcpy (line, "LISTSECRETKEYS "); - linep = &line[15]; - } - else - { - strcpy (line, "LISTKEYS "); - linep = &line[9]; - } - - if (pattern && *pattern) - { - while (*pattern) - { - const char *patlet = *pattern; - - while (*patlet) - { - switch (*patlet) - { - case '%': - *(linep++) = '%'; - *(linep++) = '2'; - *(linep++) = '5'; - break; - case ' ': - *(linep++) = '%'; - *(linep++) = '2'; - *(linep++) = '0'; - break; - case '+': - *(linep++) = '%'; - *(linep++) = '2'; - *(linep++) = 'B'; - break; - default: - *(linep++) = *patlet; - break; - } - patlet++; - } - pattern++; - } - } - *linep = '\0'; - - _gpgme_io_close (gpgsm->input_cb.fd); - _gpgme_io_close (gpgsm->output_cb.fd); - _gpgme_io_close (gpgsm->message_cb.fd); - - gpgsm->command = line; - return 0; -} - - -static GpgmeError -gpgsm_sign (void *engine, GpgmeData in, GpgmeData out, GpgmeSigMode mode, - int use_armor, int use_textmode, int include_certs, - GpgmeCtx ctx /* FIXME */) -{ - GpgsmObject gpgsm = engine; - GpgmeError err; - char *assuan_cmd; - int i; - GpgmeKey key; - - if (!gpgsm) - return mk_error (Invalid_Value); - - gpgsm->command = strdup (mode == GPGME_SIG_MODE_DETACH - ? "SIGN --detached" : "SIGN"); - if (!gpgsm->command) - return mk_error (Out_Of_Core); - - if (asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0) - return mk_error (Out_Of_Core); - err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, assuan_cmd, NULL,NULL); - free (assuan_cmd); - if (err) - return err; - - /* We must do a reset becuase we need to reset the list of signers. Note - that RESET does not reset OPTION commands. */ - err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, "RESET", NULL, NULL); - if (err) - return err; - - for (i = 0; (key = gpgme_signers_enum (ctx, i)); i++) - { - const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, - NULL, 0); - if (s && strlen (s) < 80) - { - char buf[100]; - - strcpy (stpcpy (buf, "SIGNER "), s); - err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, buf, - NULL, NULL); - } - else - err = GPGME_Invalid_Key; - gpgme_key_unref (key); - if (err) - return err; - } - - gpgsm->input_cb.data = in; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, - map_input_enc (gpgsm->input_cb.data)); - if (err) - return err; - gpgsm->output_cb.data = out; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, - use_armor ? "--armor" : 0); - if (err) - return err; - _gpgme_io_close (gpgsm->message_cb.fd); - - return 0; -} - - -static GpgmeError -gpgsm_trustlist (void *engine, const char *pattern) -{ - /* FIXME */ - return mk_error (Not_Implemented); -} - - -static GpgmeError -gpgsm_verify (void *engine, GpgmeData sig, GpgmeData signed_text, - GpgmeData plaintext) -{ - GpgsmObject gpgsm = engine; - GpgmeError err; - - if (!gpgsm) - return mk_error (Invalid_Value); - - gpgsm->command = strdup ("VERIFY"); - if (!gpgsm->command) - return mk_error (Out_Of_Core); - - gpgsm->input_cb.data = sig; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, - map_input_enc (gpgsm->input_cb.data)); - if (err) - return err; - if (plaintext) - { - /* Normal or cleartext signature. */ - gpgsm->output_cb.data = plaintext; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, - 0); - _gpgme_io_close (gpgsm->message_cb.fd); - } - else - { - /* Detached signature. */ - gpgsm->message_cb.data = signed_text; - err = gpgsm_set_fd (gpgsm->assuan_ctx, "MESSAGE", - gpgsm->message_fd_server, 0); - _gpgme_io_close (gpgsm->output_cb.fd); - } - if (err) - return err; - - return 0; -} - - static int status_cmp (const void *ap, const void *bp) { @@ -1387,6 +830,584 @@ status_handler (void *opaque, int fd) } +static GpgmeError +add_io_cb (GpgsmObject gpgsm, iocb_data_t *iocbd, GpgmeIOCb handler) +{ + GpgmeError err; + + err = (*gpgsm->io_cbs.add) (gpgsm->io_cbs.add_priv, + iocbd->fd, iocbd->dir, + handler, iocbd->data, &iocbd->tag); + if (err) + return err; + if (!iocbd->dir) + /* FIXME Kludge around poll() problem. */ + err = _gpgme_io_set_nonblocking (iocbd->fd); + return err; +} + + +static GpgmeError +start (GpgsmObject gpgsm, const char *command) +{ + GpgmeError err = 0; + + err = add_io_cb (gpgsm, &gpgsm->status_cb, status_handler); + if (gpgsm->input_cb.fd != -1) + err = add_io_cb (gpgsm, &gpgsm->input_cb, _gpgme_data_outbound_handler); + if (!err && gpgsm->output_cb.fd != -1) + err = add_io_cb (gpgsm, &gpgsm->output_cb, _gpgme_data_inbound_handler); + if (!err && gpgsm->message_cb.fd != -1) + err = add_io_cb (gpgsm, &gpgsm->message_cb, _gpgme_data_outbound_handler); + + if (!err) + err = assuan_write_line (gpgsm->assuan_ctx, command); + + return err; +} + + +static GpgmeError +gpgsm_decrypt (void *engine, GpgmeData ciph, GpgmeData plain) +{ + GpgsmObject gpgsm = engine; + GpgmeError err; + + if (!gpgsm) + return mk_error (Invalid_Value); + + gpgsm->input_cb.data = ciph; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_cb.data)); + if (err) + return mk_error (General_Error); /* FIXME */ + gpgsm->output_cb.data = plain; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, 0); + if (err) + return mk_error (General_Error); /* FIXME */ + _gpgme_io_close (gpgsm->message_cb.fd); + + err = start (engine, "DECRYPT"); + return err; +} + + +static GpgmeError +gpgsm_delete (void *engine, GpgmeKey key, int allow_secret) +{ + GpgsmObject gpgsm = engine; + GpgmeError err; + char *fpr = (char *) gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, 0); + char *linep = fpr; + char *line; + int length = 8; /* "DELKEYS " */ + + if (!fpr) + return mk_error (Invalid_Key); + + while (*linep) + { + length++; + if (*linep == '%' || *linep == ' ' || *linep == '+') + length += 2; + linep++; + } + length++; + + line = malloc (length); + if (!line) + return mk_error (Out_Of_Core); + + strcpy (line, "DELKEYS "); + linep = &line[8]; + + while (*fpr) + { + switch (*fpr) + { + case '%': + *(linep++) = '%'; + *(linep++) = '2'; + *(linep++) = '5'; + break; + case ' ': + *(linep++) = '%'; + *(linep++) = '2'; + *(linep++) = '0'; + break; + case '+': + *(linep++) = '%'; + *(linep++) = '2'; + *(linep++) = 'B'; + break; + default: + *(linep++) = *fpr; + break; + } + fpr++; + } + *linep = '\0'; + + _gpgme_io_close (gpgsm->output_cb.fd); + _gpgme_io_close (gpgsm->input_cb.fd); + _gpgme_io_close (gpgsm->message_cb.fd); + + err = start (gpgsm, line); + free (line); + + return err; +} + + +static GpgmeError +set_recipients (GpgsmObject gpgsm, GpgmeRecipients recp) +{ + GpgmeError err; + ASSUAN_CONTEXT ctx = gpgsm->assuan_ctx; + char *line; + int linelen; + struct user_id_s *r; + int valid_recipients = 0; + + linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */ + line = malloc (10 + 40 + 1); + if (!line) + return mk_error (Out_Of_Core); + strcpy (line, "RECIPIENT "); + for (r = recp->list; r; r = r->next) + { + int newlen = 11 + strlen (r->name); + if (linelen < newlen) + { + char *newline = realloc (line, newlen); + if (! newline) + { + free (line); + return mk_error (Out_Of_Core); + } + line = newline; + linelen = newlen; + } + strcpy (&line[10], r->name); + + err = gpgsm_assuan_simple_command (ctx, line, gpgsm->status.fnc, + gpgsm->status.fnc_value); + if (!err) + valid_recipients = 1; + else if (err != GPGME_Invalid_Key) + { + free (line); + return err; + } + } + free (line); + if (!valid_recipients && gpgsm->status.fnc) + gpgsm->status.fnc (gpgsm->status.fnc_value, GPGME_STATUS_NO_RECP, ""); + return 0; +} + + +static GpgmeError +gpgsm_encrypt (void *engine, GpgmeRecipients recp, GpgmeData plain, + GpgmeData ciph, int use_armor) +{ + GpgsmObject gpgsm = engine; + GpgmeError err; + + if (!gpgsm) + return mk_error (Invalid_Value); + if (!recp) + return mk_error (Not_Implemented); + + gpgsm->input_cb.data = plain; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_cb.data)); + if (err) + return err; + gpgsm->output_cb.data = ciph; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + use_armor ? "--armor" : 0); + if (err) + return err; + _gpgme_io_close (gpgsm->message_cb.fd); + + err = set_recipients (gpgsm, recp); + + if (!err) + err = start (gpgsm, "ENCRYPT"); + + return err; +} + + +static GpgmeError +gpgsm_export (void *engine, GpgmeRecipients recp, GpgmeData keydata, + int use_armor) +{ + GpgsmObject gpgsm = engine; + GpgmeError err = 0; + char *cmd = NULL; + int cmdi; + int cmdlen = 32; + + if (!gpgsm) + return mk_error (Invalid_Value); + + cmd = malloc (cmdlen); + if (!cmd) + return mk_error (Out_Of_Core); + strcpy (cmd, "EXPORT"); + cmdi = 6; + + if (recp) + { + void *ec; + const char *s; + + err = gpgme_recipients_enum_open (recp, &ec); + while (!err && (s = gpgme_recipients_enum_read (recp, &ec))) + { + int slen = strlen (s); + /* New string is old string + ' ' + s + '\0'. */ + if (cmdlen < cmdi + 1 + slen + 1) + { + char *newcmd = realloc (cmd, cmdlen * 2); + if (!newcmd) + { + free (cmd); + return mk_error (Out_Of_Core); + } + cmd = newcmd; + cmdlen *= 2; + } + cmd[cmdi++] = ' '; + strcpy (cmd + cmdi, s); + cmdi += slen; + } + if (!err) + err = gpgme_recipients_enum_close (recp, &ec); + if (err) + return err; + } + + gpgsm->output_cb.data = keydata; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + use_armor ? "--armor" : 0); + if (err) + return err; + _gpgme_io_close (gpgsm->input_cb.fd); + _gpgme_io_close (gpgsm->message_cb.fd); + + err = start (gpgsm, cmd); + free (cmd); + return err; +} + + +static GpgmeError +gpgsm_genkey (void *engine, GpgmeData help_data, int use_armor, + GpgmeData pubkey, GpgmeData seckey) +{ + GpgsmObject gpgsm = engine; + GpgmeError err; + + if (!gpgsm || !pubkey || seckey) + return mk_error (Invalid_Value); + + gpgsm->input_cb.data = help_data; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_cb.data)); + if (err) + return err; + gpgsm->output_cb.data = pubkey; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + use_armor ? "--armor" : 0); + if (err) + return err; + _gpgme_io_close (gpgsm->message_cb.fd); + + err = start (gpgsm, "GENKEY"); + return err; +} + + +static GpgmeError +gpgsm_import (void *engine, GpgmeData keydata) +{ + GpgsmObject gpgsm = engine; + GpgmeError err; + + if (!gpgsm) + return mk_error (Invalid_Value); + + gpgsm->input_cb.data = keydata; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_cb.data)); + if (err) + return err; + _gpgme_io_close (gpgsm->output_cb.fd); + _gpgme_io_close (gpgsm->message_cb.fd); + + err = start (gpgsm, "IMPORT"); + return err; +} + + +static GpgmeError +gpgsm_keylist (void *engine, const char *pattern, int secret_only, + int keylist_mode) +{ + GpgsmObject gpgsm = engine; + char *line; + GpgmeError err; + + if (!pattern) + pattern = ""; + + if (asprintf (&line, "OPTION list-mode=%d", (keylist_mode & 3)) < 0) + return mk_error (Out_Of_Core); + err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); + free (line); + if (err) + return err; + + /* Length is "LISTSECRETKEYS " + p + '\0'. */ + line = malloc (15 + strlen (pattern) + 1); + if (!line) + return mk_error (Out_Of_Core); + if (secret_only) + { + strcpy (line, "LISTSECRETKEYS "); + strcpy (&line[15], pattern); + } + else + { + strcpy (line, "LISTKEYS "); + strcpy (&line[9], pattern); + } + + _gpgme_io_close (gpgsm->input_cb.fd); + _gpgme_io_close (gpgsm->output_cb.fd); + _gpgme_io_close (gpgsm->message_cb.fd); + + err = start (gpgsm, line); + free (line); + return err; +} + + +static GpgmeError +gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only, + int reserved, int keylist_mode) +{ + GpgsmObject gpgsm = engine; + char *line; + GpgmeError err; + /* Length is "LISTSECRETKEYS " + p + '\0'. */ + int length = 15 + 1; + char *linep; + + if (reserved) + return mk_error (Invalid_Value); + + if (asprintf (&line, "OPTION list-mode=%d", (keylist_mode & 3)) < 0) + return mk_error (Out_Of_Core); + err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); + free (line); + if (err) + return err; + + if (pattern && *pattern) + { + const char **pat = pattern; + + while (*pat) + { + const char *patlet = *pat; + + while (*patlet) + { + length++; + if (*patlet == '%' || *patlet == ' ' || *patlet == '+') + length += 2; + patlet++; + } + pat++; + /* This will allocate one byte more than necessary. */ + length++; + } + } + line = malloc (length); + if (!line) + return mk_error (Out_Of_Core); + if (secret_only) + { + strcpy (line, "LISTSECRETKEYS "); + linep = &line[15]; + } + else + { + strcpy (line, "LISTKEYS "); + linep = &line[9]; + } + + if (pattern && *pattern) + { + while (*pattern) + { + const char *patlet = *pattern; + + while (*patlet) + { + switch (*patlet) + { + case '%': + *(linep++) = '%'; + *(linep++) = '2'; + *(linep++) = '5'; + break; + case ' ': + *(linep++) = '%'; + *(linep++) = '2'; + *(linep++) = '0'; + break; + case '+': + *(linep++) = '%'; + *(linep++) = '2'; + *(linep++) = 'B'; + break; + default: + *(linep++) = *patlet; + break; + } + patlet++; + } + pattern++; + } + } + *linep = '\0'; + + _gpgme_io_close (gpgsm->input_cb.fd); + _gpgme_io_close (gpgsm->output_cb.fd); + _gpgme_io_close (gpgsm->message_cb.fd); + + err = start (gpgsm, line); + free (line); + return err; +} + + +static GpgmeError +gpgsm_sign (void *engine, GpgmeData in, GpgmeData out, GpgmeSigMode mode, + int use_armor, int use_textmode, int include_certs, + GpgmeCtx ctx /* FIXME */) +{ + GpgsmObject gpgsm = engine; + GpgmeError err; + char *assuan_cmd; + int i; + GpgmeKey key; + + if (!gpgsm) + return mk_error (Invalid_Value); + + if (asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0) + return mk_error (Out_Of_Core); + err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, assuan_cmd, NULL,NULL); + free (assuan_cmd); + if (err) + return err; + + /* We must do a reset becuase we need to reset the list of signers. Note + that RESET does not reset OPTION commands. */ + err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, "RESET", NULL, NULL); + if (err) + return err; + + for (i = 0; (key = gpgme_signers_enum (ctx, i)); i++) + { + const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, + NULL, 0); + if (s && strlen (s) < 80) + { + char buf[100]; + + strcpy (stpcpy (buf, "SIGNER "), s); + err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, buf, + NULL, NULL); + } + else + err = GPGME_Invalid_Key; + gpgme_key_unref (key); + if (err) + return err; + } + + gpgsm->input_cb.data = in; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_cb.data)); + if (err) + return err; + gpgsm->output_cb.data = out; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + use_armor ? "--armor" : 0); + if (err) + return err; + _gpgme_io_close (gpgsm->message_cb.fd); + + err = start (gpgsm, mode == GPGME_SIG_MODE_DETACH + ? "SIGN --detached" : "SIGN"); + return err; +} + + +static GpgmeError +gpgsm_trustlist (void *engine, const char *pattern) +{ + /* FIXME */ + return mk_error (Not_Implemented); +} + + +static GpgmeError +gpgsm_verify (void *engine, GpgmeData sig, GpgmeData signed_text, + GpgmeData plaintext) +{ + GpgsmObject gpgsm = engine; + GpgmeError err; + + if (!gpgsm) + return mk_error (Invalid_Value); + + gpgsm->input_cb.data = sig; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, + map_input_enc (gpgsm->input_cb.data)); + if (err) + return err; + if (plaintext) + { + /* Normal or cleartext signature. */ + gpgsm->output_cb.data = plaintext; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, + 0); + _gpgme_io_close (gpgsm->message_cb.fd); + } + else + { + /* Detached signature. */ + gpgsm->message_cb.data = signed_text; + err = gpgsm_set_fd (gpgsm->assuan_ctx, "MESSAGE", + gpgsm->message_fd_server, 0); + _gpgme_io_close (gpgsm->output_cb.fd); + } + + if (!err) + err = start (gpgsm, "VERIFY"); + + return err; +} + + static void gpgsm_set_status_handler (void *engine, GpgmeStatusHandler fnc, void *fnc_value) @@ -1411,50 +1432,6 @@ gpgsm_set_colon_line_handler (void *engine, GpgmeColonLineHandler fnc, } -static GpgmeError -add_io_cb (GpgsmObject gpgsm, iocb_data_t *iocbd, GpgmeIOCb handler) -{ - GpgmeError err; - - err = (*gpgsm->io_cbs.add) (gpgsm->io_cbs.add_priv, - iocbd->fd, iocbd->dir, - handler, iocbd->data, &iocbd->tag); - if (err) - return err; - if (!iocbd->dir) - /* FIXME Kludge around poll() problem. */ - err = _gpgme_io_set_nonblocking (iocbd->fd); - return err; -} - - -static GpgmeError -gpgsm_start (void *engine, void *opaque) -{ - GpgsmObject gpgsm = engine; - GpgmeError err = 0; - pid_t pid; - - if (!gpgsm) - return mk_error (Invalid_Value); - - pid = assuan_get_pid (gpgsm->assuan_ctx); - - err = add_io_cb (gpgsm, &gpgsm->status_cb, status_handler); - if (gpgsm->input_cb.fd != -1) - err = add_io_cb (gpgsm, &gpgsm->input_cb, _gpgme_data_outbound_handler); - if (!err && gpgsm->output_cb.fd != -1) - err = add_io_cb (gpgsm, &gpgsm->output_cb, _gpgme_data_inbound_handler); - if (!err && gpgsm->message_cb.fd != -1) - err = add_io_cb (gpgsm, &gpgsm->message_cb, _gpgme_data_outbound_handler); - - if (!err) - err = assuan_write_line (gpgsm->assuan_ctx, gpgsm->command); - - return err; -} - - static void gpgsm_set_io_cbs (void *engine, struct GpgmeIOCbs *io_cbs) { @@ -1500,7 +1477,6 @@ struct engine_ops _gpgme_engine_ops_gpgsm = gpgsm_sign, gpgsm_trustlist, gpgsm_verify, - gpgsm_start, gpgsm_set_io_cbs, gpgsm_io_event }; diff --git a/gpgme/engine.c b/gpgme/engine.c index eb87eab5..e96af138 100644 --- a/gpgme/engine.c +++ b/gpgme/engine.c @@ -426,19 +426,6 @@ _gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, } -GpgmeError -_gpgme_engine_start (EngineObject engine, void *opaque) -{ - if (!engine) - return mk_error (Invalid_Value); - - if (!engine->ops->start) - return mk_error (Not_Implemented); - - return (*engine->ops->start) (engine->engine, opaque); -} - - void _gpgme_engine_set_io_cbs (EngineObject engine, struct GpgmeIOCbs *io_cbs) diff --git a/gpgme/engine.h b/gpgme/engine.h index 27fc5ac8..54af330c 100644 --- a/gpgme/engine.h +++ b/gpgme/engine.h @@ -81,7 +81,6 @@ GpgmeError _gpgme_engine_op_trustlist (EngineObject engine, const char *pattern); GpgmeError _gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, GpgmeData signed_text, GpgmeData plaintext); -GpgmeError _gpgme_engine_start (EngineObject engine, void *opaque); void _gpgme_engine_set_io_cbs (EngineObject engine, struct GpgmeIOCbs *io_cbs); diff --git a/gpgme/export.c b/gpgme/export.c index ad4984de..93cd098c 100644 --- a/gpgme/export.c +++ b/gpgme/export.c @@ -1,25 +1,26 @@ /* export.c - encrypt functions - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002 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 +#endif #include #include #include @@ -61,8 +62,6 @@ _gpgme_op_export_start (GpgmeCtx ctx, int synchronous, _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); err = _gpgme_engine_op_export (ctx->engine, recp, keydata, ctx->use_armor); - if (!err) - err = _gpgme_engine_start (ctx->engine, ctx); leave: if (err) diff --git a/gpgme/genkey.c b/gpgme/genkey.c index b4e67084..a4633da8 100644 --- a/gpgme/genkey.c +++ b/gpgme/genkey.c @@ -130,9 +130,6 @@ _gpgme_op_genkey_start (GpgmeCtx ctx, int synchronous, const char *parms, err = _gpgme_engine_op_genkey (ctx->engine, ctx->help_data_1, ctx->use_armor, pubkey, seckey); - if (!err) - err = _gpgme_engine_start (ctx->engine, ctx); - leave: if (err) { diff --git a/gpgme/import.c b/gpgme/import.c index f95086a2..9776cb7e 100644 --- a/gpgme/import.c +++ b/gpgme/import.c @@ -1,25 +1,26 @@ /* import.c - encrypt functions - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002 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 +#endif #include #include #include @@ -195,10 +196,7 @@ _gpgme_op_import_start (GpgmeCtx ctx, int synchronous, GpgmeData keydata) _gpgme_engine_set_status_handler (ctx->engine, import_status_handler, ctx); _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); - _gpgme_engine_op_import (ctx->engine, keydata); - - if (!err) - err = _gpgme_engine_start (ctx->engine, ctx); + err = _gpgme_engine_op_import (ctx->engine, keydata); leave: if (err) diff --git a/gpgme/key.c b/gpgme/key.c index 377c714b..dcd57714 100644 --- a/gpgme/key.c +++ b/gpgme/key.c @@ -1220,6 +1220,8 @@ gpgme_get_key (GpgmeCtx ctx, const char *fpr, GpgmeKey *r_key, } } + /* We need our own context because we have to avoid the user's I/O + callback handlers. */ /* Fixme: This can be optimized by keeping an internal context used for such key listings. */ err = gpgme_new (&listctx); diff --git a/gpgme/keylist.c b/gpgme/keylist.c index ac6bc4bb..ed753414 100644 --- a/gpgme/keylist.c +++ b/gpgme/keylist.c @@ -772,9 +772,6 @@ gpgme_op_keylist_start (GpgmeCtx ctx, const char *pattern, int secret_only) err = _gpgme_engine_op_keylist (ctx->engine, pattern, secret_only, ctx->keylist_mode); - if (!err) /* And kick off the process. */ - err = _gpgme_engine_start (ctx->engine, ctx); - leave: if (err) { @@ -826,10 +823,6 @@ gpgme_op_keylist_ext_start (GpgmeCtx ctx, const char *pattern[], err = _gpgme_engine_op_keylist_ext (ctx->engine, pattern, secret_only, reserved, ctx->keylist_mode); - /* And kick off the process. */ - if (!err) - err = _gpgme_engine_start (ctx->engine, ctx); - leave: if (err) { diff --git a/gpgme/rungpg.c b/gpgme/rungpg.c index 88afaea9..7677941f 100644 --- a/gpgme/rungpg.c +++ b/gpgme/rungpg.c @@ -1079,9 +1079,8 @@ colon_line_handler (void *opaque, int fd) static GpgmeError -gpg_start (void *engine, void *opaque) +start (GpgObject gpg) { - GpgObject gpg = engine; GpgmeError rc; int i, n; int status; @@ -1223,6 +1222,8 @@ gpg_decrypt (void *engine, GpgmeData ciph, GpgmeData plain) if (!err) err = add_data (gpg, ciph, 0, 0); + if (!err) + start (gpg); return err; } @@ -1245,6 +1246,8 @@ gpg_delete (void *engine, GpgmeKey key, int allow_secret) err = add_arg (gpg, s); } + if (!err) + start (gpg); return err; } @@ -1297,6 +1300,8 @@ gpg_edit (void *engine, GpgmeKey key, GpgmeData out, GpgmeCtx ctx /* FIXME */) else err = add_arg (gpg, s); } + if (!err) + err = start (gpg); return err; } @@ -1357,9 +1362,13 @@ gpg_encrypt (void *engine, GpgmeRecipients recp, GpgmeData plain, if (!err) err = add_data (gpg, plain, 0, 0); + if (!err) + err = start (gpg); + return err; } + static GpgmeError gpg_encrypt_sign (void *engine, GpgmeRecipients recp, GpgmeData plain, GpgmeData ciph, int use_armor, GpgmeCtx ctx /* FIXME */) @@ -1396,9 +1405,13 @@ gpg_encrypt_sign (void *engine, GpgmeRecipients recp, GpgmeData plain, if (!err) err = add_data (gpg, plain, 0, 0); + if (!err) + err = start (gpg); + return err; } + static GpgmeError gpg_export (void *engine, GpgmeRecipients recp, GpgmeData keydata, int use_armor) @@ -1426,6 +1439,9 @@ gpg_export (void *engine, GpgmeRecipients recp, GpgmeData keydata, err = gpgme_recipients_enum_close (recp, &ec); } + if (!err) + err = start (gpg); + return err; } @@ -1453,6 +1469,9 @@ gpg_genkey (void *engine, GpgmeData help_data, int use_armor, if (!err) err = add_data (gpg, help_data, 0, 0); + if (!err) + err = start (gpg); + return err; } @@ -1467,6 +1486,9 @@ gpg_import (void *engine, GpgmeData keydata) if (!err) err = add_data (gpg, keydata, 0, 0); + if (!err) + err = start (gpg); + return err; } @@ -1496,6 +1518,9 @@ gpg_keylist (void *engine, const char *pattern, int secret_only, if (!err && pattern && *pattern) err = add_arg (gpg, pattern); + if (!err) + err = start (gpg); + return err; } @@ -1531,6 +1556,9 @@ gpg_keylist_ext (void *engine, const char *pattern[], int secret_only, err = add_arg (gpg, *(pattern++)); } + if (!err) + err = start (gpg); + return err; } @@ -1565,6 +1593,9 @@ gpg_sign (void *engine, GpgmeData in, GpgmeData out, GpgmeSigMode mode, if (!err) err = add_data (gpg, out, 1, 1); + if (!err) + start (gpg); + return err; } @@ -1584,6 +1615,9 @@ gpg_trustlist (void *engine, const char *pattern) if (!err) err = add_arg (gpg, pattern); + if (!err) + err = start (gpg); + return err; } @@ -1624,6 +1658,10 @@ gpg_verify (void *engine, GpgmeData sig, GpgmeData signed_text, err = add_data (gpg, signed_text, 0, 0); } } + + if (!err) + err = start (gpg); + return err; } @@ -1664,7 +1702,6 @@ struct engine_ops _gpgme_engine_ops_gpg = gpg_sign, gpg_trustlist, gpg_verify, - gpg_start, gpg_set_io_cbs, gpg_io_event }; diff --git a/gpgme/sign.c b/gpgme/sign.c index 58837d94..d45699b0 100644 --- a/gpgme/sign.c +++ b/gpgme/sign.c @@ -1,25 +1,26 @@ /* sign.c - signing functions - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002 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 +#endif #include #include #include @@ -52,9 +53,9 @@ _gpgme_release_sign_result (SignResult result) } /* Parse the args and save the information - * - * in an XML structure. With args of NULL the xml structure is closed. - */ + + in an XML structure. With args of NULL the xml structure is + closed. */ static void append_xml_siginfo (GpgmeData *rdh, char *args) { @@ -204,13 +205,10 @@ _gpgme_op_sign_start (GpgmeCtx ctx, int synchronous, ctx); _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); - _gpgme_engine_op_sign (ctx->engine, in, out, mode, ctx->use_armor, - ctx->use_textmode, ctx->include_certs, - ctx /* FIXME */); + err = _gpgme_engine_op_sign (ctx->engine, in, out, mode, ctx->use_armor, + ctx->use_textmode, ctx->include_certs, + ctx /* FIXME */); - /* And kick off the process. */ - err = _gpgme_engine_start (ctx->engine, ctx); - leave: if (err) { diff --git a/gpgme/trustlist.c b/gpgme/trustlist.c index 60caa4c2..5c4a8489 100644 --- a/gpgme/trustlist.c +++ b/gpgme/trustlist.c @@ -1,25 +1,26 @@ /* trustlist.c - key listing - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ + Copyright (C) 2000 Werner Koch (dd9jn) + Copyright (C) 2001, 2002 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 +#endif #include #include #include @@ -68,19 +69,17 @@ trustlist_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args) } -/* - * This handler is used to parse the output of --list-trust-path: - * Format: - * level:keyid:type:recno:ot:val:mc:cc:name: - * With TYPE = U for a user ID - * K for a key - * The RECNO is either the one of the dir record or the one of the uid record. - * OT is the the usual trust letter and only availabel on K lines. - * VAL is the calcualted validity - * MC is the marginal trust counter and only available on U lines - * CC is the same for the complete count - * NAME ist the username and only printed on U lines - */ +/* This handler is used to parse the output of --list-trust-path: + Format: + level:keyid:type:recno:ot:val:mc:cc:name: + With TYPE = U for a user ID + K for a key + The RECNO is either the one of the dir record or the one of the uid + record. OT is the the usual trust letter and only availabel on K + lines. VAL is the calcualted validity MC is the marginal trust + counter and only available on U lines CC is the same for the + complete count NAME ist the username and only printed on U + lines. */ static void trustlist_colon_handler (GpgmeCtx ctx, char *line) { @@ -193,9 +192,6 @@ gpgme_op_trustlist_start (GpgmeCtx ctx, const char *pattern, int max_level) err =_gpgme_engine_op_trustlist (ctx->engine, pattern); - if (!err) /* And kick off the process. */ - err = _gpgme_engine_start (ctx->engine, ctx); - leave: if (err) { diff --git a/gpgme/verify.c b/gpgme/verify.c index b3d7314f..a510d398 100644 --- a/gpgme/verify.c +++ b/gpgme/verify.c @@ -384,8 +384,6 @@ _gpgme_op_verify_start (GpgmeCtx ctx, int synchronous, goto leave; } err = _gpgme_engine_op_verify (ctx->engine, sig, signed_text, plaintext); - if (!err) /* And kick off the process. */ - err = _gpgme_engine_start (ctx->engine, ctx); leave: if (err)