* 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-19 Marcus Brinkmann <marcus@g10code.de>
+
+ * 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 <wk@gnupg.org>
* keylist.c (set_mainkey_capability): Handle 'd' and 'D' used
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)
{
/* 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 <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
_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)
/* 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 <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
_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)
{
/* 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
- */
-
-#ifdef HAVE_CONFIG_H
+ 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 <config.h>
#endif
#include <stddef.h>
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)
{
/* 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 <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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)
{
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);
iocb_data_t message_cb;
int message_fd_server;
- char *command;
-
struct
{
GpgmeStatusHandler fnc;
assuan_disconnect (gpgsm->assuan_ctx);
free (gpgsm->colon.attic.line);
- free (gpgsm->command);
free (gpgsm);
}
}
+static int
+status_cmp (const void *ap, const void *bp)
+{
+ const struct status_table_s *a = ap;
+ const struct status_table_s *b = bp;
+
+ return strcmp (a->name, b->name);
+}
+
+
+static GpgmeStatusCode
+parse_status (const char *name)
+{
+ struct status_table_s t, *r;
+ t.name = name;
+ r = bsearch (&t, status_table, DIM(status_table) - 1,
+ sizeof t, status_cmp);
+ return r ? r->code : -1;
+}
+
+
+static void
+status_handler (void *opaque, int fd)
+{
+ AssuanError err;
+ GpgsmObject gpgsm = opaque;
+ char *line;
+ size_t linelen;
+
+ do
+ {
+ err = assuan_read_line (gpgsm->assuan_ctx, &line, &linelen);
+
+ if (err
+ || (linelen >= 2
+ && line[0] == 'O' && line[1] == 'K'
+ && (line[2] == '\0' || line[2] == ' '))
+ || (linelen >= 3
+ && line[0] == 'E' && line[1] == 'R' && line[2] == 'R'
+ && (line[3] == '\0' || line[3] == ' ')))
+ {
+ /* XXX: If an error occured, find out what happened, then
+ save the error value before running the status handler
+ (so it takes precedence). */
+ if (!err && line[0] == 'E' && line[3] == ' ')
+ {
+ err = map_assuan_error (atoi (&line[4]));
+ if (!err)
+ err = mk_error (General_Error);
+ }
+ if (err)
+ {
+ /* XXX Kludge ahead. We really, really, really must not
+ make use of status.fnc_value. */
+ GpgmeCtx ctx = (GpgmeCtx) gpgsm->status.fnc_value;
+ if (!ctx->error)
+ ctx->error = err;
+ }
+
+ if (gpgsm->status.fnc)
+ gpgsm->status.fnc (gpgsm->status.fnc_value, GPGME_STATUS_EOF, "");
+ if (gpgsm->colon.fnc && gpgsm->colon.any )
+ {
+ /* We must tell a colon fucntion about the EOF. We do
+ this only when we have seen any data lines. Note
+ that this inlined use of colon data lines will
+ eventually be changed into using a regular data
+ channel. */
+ gpgsm->colon.any = 0;
+ gpgsm->colon.fnc (gpgsm->colon.fnc_value, NULL);
+ }
+
+ /* XXX: Try our best to terminate the connection. */
+ if (err)
+ assuan_write_line (gpgsm->assuan_ctx, "BYE");
+
+ _gpgme_io_close (gpgsm->status_cb.fd);
+ return;
+ }
+
+ if (linelen > 2
+ && line[0] == 'D' && line[1] == ' '
+ && gpgsm->colon.fnc)
+ {
+ /* We are using the colon handler even for plain inline data
+ - strange name for that function but for historic reasons
+ we keep it. */
+ /* FIXME We can't use this for binary data because we
+ assume this is a string. For the current usage of colon
+ output it is correct. */
+ unsigned char *src = line + 2;
+ unsigned char *end = line + linelen;
+ unsigned char *dst;
+ unsigned char **aline = &gpgsm->colon.attic.line;
+ int *alinelen = &gpgsm->colon.attic.linelen;
+
+ if (gpgsm->colon.attic.linesize
+ < *alinelen + linelen + 1)
+ {
+ unsigned char *newline = realloc (*aline,
+ *alinelen + linelen + 1);
+ if (!newline)
+ {
+ _gpgme_io_close (gpgsm->status_cb.fd);
+ return;
+ }
+ *aline = newline;
+ gpgsm->colon.attic.linesize += linelen + 1;
+ }
+
+ dst = *aline + *alinelen;
+
+ while (src < end)
+ {
+ if (*src == '%' && src + 2 < end)
+ {
+ /* Handle escaped characters. */
+ ++src;
+ *dst = xtoi_2 (src);
+ (*alinelen)++;
+ src += 2;
+ }
+ else
+ {
+ *dst = *src++;
+ (*alinelen)++;
+ }
+
+ if (*dst == '\n')
+ {
+ /* Terminate the pending line, pass it to the colon
+ handler and reset it. */
+
+ gpgsm->colon.any = 1;
+ if (*alinelen > 1 && *(dst - 1) == '\r')
+ dst--;
+ *dst = '\0';
+
+ /* FIXME How should we handle the return code? */
+ gpgsm->colon.fnc (gpgsm->colon.fnc_value, *aline);
+ dst = *aline;
+ *alinelen = 0;
+ }
+ else
+ dst++;
+ }
+ }
+ else if (linelen > 2
+ && line[0] == 'S' && line[1] == ' ')
+ {
+ char *rest;
+ GpgmeStatusCode r;
+
+ rest = strchr (line + 2, ' ');
+ if (!rest)
+ rest = line + linelen; /* set to an empty string */
+ else
+ *(rest++) = 0;
+
+ r = parse_status (line + 2);
+
+ if (r >= 0)
+ {
+ if (gpgsm->status.fnc)
+ gpgsm->status.fnc (gpgsm->status.fnc_value, r, rest);
+ }
+ else
+ fprintf (stderr, "[UNKNOWN STATUS]%s %s", line + 2, rest);
+ }
+ }
+ while (assuan_pending_line (gpgsm->assuan_ctx));
+}
+
+
+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)
{
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));
return mk_error (General_Error); /* FIXME */
_gpgme_io_close (gpgsm->message_cb.fd);
- return 0;
+ err = start (engine, "DECRYPT");
+ return err;
}
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;
}
*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;
+ err = start (gpgsm, line);
+ free (line);
+
+ return err;
}
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));
_gpgme_io_close (gpgsm->message_cb.fd);
err = set_recipients (gpgsm, recp);
- if (err)
- return err;
- return 0;
+ if (!err)
+ err = start (gpgsm, "ENCRYPT");
+
+ return 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);
_gpgme_io_close (gpgsm->input_cb.fd);
_gpgme_io_close (gpgsm->message_cb.fd);
- return 0;
+ err = start (gpgsm, cmd);
+ free (cmd);
+ return 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));
return err;
_gpgme_io_close (gpgsm->message_cb.fd);
- return 0;
+ err = start (gpgsm, "GENKEY");
+ return 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));
_gpgme_io_close (gpgsm->output_cb.fd);
_gpgme_io_close (gpgsm->message_cb.fd);
- return 0;
+ err = start (gpgsm, "IMPORT");
+ return err;
}
_gpgme_io_close (gpgsm->output_cb.fd);
_gpgme_io_close (gpgsm->message_cb.fd);
- gpgsm->command = line;
- return 0;
+ err = start (gpgsm, line);
+ free (line);
+ return err;
}
_gpgme_io_close (gpgsm->output_cb.fd);
_gpgme_io_close (gpgsm->message_cb.fd);
- gpgsm->command = line;
- return 0;
+ err = start (gpgsm, line);
+ free (line);
+ return err;
}
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);
return err;
_gpgme_io_close (gpgsm->message_cb.fd);
- return 0;
+ err = start (gpgsm, mode == GPGME_SIG_MODE_DETACH
+ ? "SIGN --detached" : "SIGN");
+ return 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));
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)
-{
- const struct status_table_s *a = ap;
- const struct status_table_s *b = bp;
-
- return strcmp (a->name, b->name);
-}
-
-
-static GpgmeStatusCode
-parse_status (const char *name)
-{
- struct status_table_s t, *r;
- t.name = name;
- r = bsearch (&t, status_table, DIM(status_table) - 1,
- sizeof t, status_cmp);
- return r ? r->code : -1;
-}
-
-
-static void
-status_handler (void *opaque, int fd)
-{
- AssuanError err;
- GpgsmObject gpgsm = opaque;
- char *line;
- size_t linelen;
-
- do
- {
- err = assuan_read_line (gpgsm->assuan_ctx, &line, &linelen);
-
- if (err
- || (linelen >= 2
- && line[0] == 'O' && line[1] == 'K'
- && (line[2] == '\0' || line[2] == ' '))
- || (linelen >= 3
- && line[0] == 'E' && line[1] == 'R' && line[2] == 'R'
- && (line[3] == '\0' || line[3] == ' ')))
- {
- /* XXX: If an error occured, find out what happened, then
- save the error value before running the status handler
- (so it takes precedence). */
- if (!err && line[0] == 'E' && line[3] == ' ')
- {
- err = map_assuan_error (atoi (&line[4]));
- if (!err)
- err = mk_error (General_Error);
- }
- if (err)
- {
- /* XXX Kludge ahead. We really, really, really must not
- make use of status.fnc_value. */
- GpgmeCtx ctx = (GpgmeCtx) gpgsm->status.fnc_value;
- if (!ctx->error)
- ctx->error = err;
- }
-
- if (gpgsm->status.fnc)
- gpgsm->status.fnc (gpgsm->status.fnc_value, GPGME_STATUS_EOF, "");
- if (gpgsm->colon.fnc && gpgsm->colon.any )
- {
- /* We must tell a colon fucntion about the EOF. We do
- this only when we have seen any data lines. Note
- that this inlined use of colon data lines will
- eventually be changed into using a regular data
- channel. */
- gpgsm->colon.any = 0;
- gpgsm->colon.fnc (gpgsm->colon.fnc_value, NULL);
- }
-
- /* XXX: Try our best to terminate the connection. */
- if (err)
- assuan_write_line (gpgsm->assuan_ctx, "BYE");
-
- _gpgme_io_close (gpgsm->status_cb.fd);
- return;
- }
-
- if (linelen > 2
- && line[0] == 'D' && line[1] == ' '
- && gpgsm->colon.fnc)
- {
- /* We are using the colon handler even for plain inline data
- - strange name for that function but for historic reasons
- we keep it. */
- /* FIXME We can't use this for binary data because we
- assume this is a string. For the current usage of colon
- output it is correct. */
- unsigned char *src = line + 2;
- unsigned char *end = line + linelen;
- unsigned char *dst;
- unsigned char **aline = &gpgsm->colon.attic.line;
- int *alinelen = &gpgsm->colon.attic.linelen;
-
- if (gpgsm->colon.attic.linesize
- < *alinelen + linelen + 1)
- {
- unsigned char *newline = realloc (*aline,
- *alinelen + linelen + 1);
- if (!newline)
- {
- _gpgme_io_close (gpgsm->status_cb.fd);
- return;
- }
- *aline = newline;
- gpgsm->colon.attic.linesize += linelen + 1;
- }
- dst = *aline + *alinelen;
-
- while (src < end)
- {
- if (*src == '%' && src + 2 < end)
- {
- /* Handle escaped characters. */
- ++src;
- *dst = xtoi_2 (src);
- (*alinelen)++;
- src += 2;
- }
- else
- {
- *dst = *src++;
- (*alinelen)++;
- }
-
- if (*dst == '\n')
- {
- /* Terminate the pending line, pass it to the colon
- handler and reset it. */
-
- gpgsm->colon.any = 1;
- if (*alinelen > 1 && *(dst - 1) == '\r')
- dst--;
- *dst = '\0';
-
- /* FIXME How should we handle the return code? */
- gpgsm->colon.fnc (gpgsm->colon.fnc_value, *aline);
- dst = *aline;
- *alinelen = 0;
- }
- else
- dst++;
- }
- }
- else if (linelen > 2
- && line[0] == 'S' && line[1] == ' ')
- {
- char *rest;
- GpgmeStatusCode r;
-
- rest = strchr (line + 2, ' ');
- if (!rest)
- rest = line + linelen; /* set to an empty string */
- else
- *(rest++) = 0;
-
- r = parse_status (line + 2);
+ if (!err)
+ err = start (gpgsm, "VERIFY");
- if (r >= 0)
- {
- if (gpgsm->status.fnc)
- gpgsm->status.fnc (gpgsm->status.fnc_value, r, rest);
- }
- else
- fprintf (stderr, "[UNKNOWN STATUS]%s %s", line + 2, rest);
- }
- }
- while (assuan_pending_line (gpgsm->assuan_ctx));
+ return err;
}
}
-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)
{
gpgsm_sign,
gpgsm_trustlist,
gpgsm_verify,
- gpgsm_start,
gpgsm_set_io_cbs,
gpgsm_io_event
};
}
-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)
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);
/* 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 <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
_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)
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)
{
/* 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 <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
_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)
}
}
+ /* 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);
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)
{
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)
{
static GpgmeError
-gpg_start (void *engine, void *opaque)
+start (GpgObject gpg)
{
- GpgObject gpg = engine;
GpgmeError rc;
int i, n;
int status;
if (!err)
err = add_data (gpg, ciph, 0, 0);
+ if (!err)
+ start (gpg);
return err;
}
err = add_arg (gpg, s);
}
+ if (!err)
+ start (gpg);
return err;
}
else
err = add_arg (gpg, s);
}
+ if (!err)
+ err = start (gpg);
return err;
}
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 */)
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)
err = gpgme_recipients_enum_close (recp, &ec);
}
+ if (!err)
+ err = start (gpg);
+
return err;
}
if (!err)
err = add_data (gpg, help_data, 0, 0);
+ if (!err)
+ err = start (gpg);
+
return err;
}
if (!err)
err = add_data (gpg, keydata, 0, 0);
+ if (!err)
+ err = start (gpg);
+
return err;
}
if (!err && pattern && *pattern)
err = add_arg (gpg, pattern);
+ if (!err)
+ err = start (gpg);
+
return err;
}
err = add_arg (gpg, *(pattern++));
}
+ if (!err)
+ err = start (gpg);
+
return err;
}
if (!err)
err = add_data (gpg, out, 1, 1);
+ if (!err)
+ start (gpg);
+
return err;
}
if (!err)
err = add_arg (gpg, pattern);
+ if (!err)
+ err = start (gpg);
+
return err;
}
err = add_data (gpg, signed_text, 0, 0);
}
}
+
+ if (!err)
+ err = start (gpg);
+
return err;
}
gpg_sign,
gpg_trustlist,
gpg_verify,
- gpg_start,
gpg_set_io_cbs,
gpg_io_event
};
/* 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 <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}
/* Parse the args and save the information
- * <type> <pubkey algo> <hash algo> <class> <timestamp> <key fpr>
- * in an XML structure. With args of NULL the xml structure is closed.
- */
+ <type> <pubkey algo> <hash algo> <class> <timestamp> <key fpr>
+ in an XML structure. With args of NULL the xml structure is
+ closed. */
static void
append_xml_siginfo (GpgmeData *rdh, char *args)
{
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)
{
/* 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 <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}
-/*
- * 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)
{
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)
{
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)