gpgme/gpgme/engine.c
Marcus Brinkmann 8f8c78d534 doc/
2003-05-29  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.texi (Exporting Keys): Change and document prototypes.
	Add new gpgme_op_export_ext and gpgme_op_export_ext_start
	variants.
	(Selecting Recipients): Section removed.
	(Encrypting a Plaintext): Change prototypes and document the
	changes.

gpgme/
2003-05-29  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.h (gpgme_op_export_start): Change second arg to const char *.
	(gpgme_op_export): Likewise.
	(gpgme_op_export_ext_start): New prototype.
	(gpgme_op_export_ext): Likewise.
	* engine.h: Likewise for _gpgme_engine_op_export and
	_gpgme_engine_op_export_ext.
	* engine-backend.h (struct engine_ops): Change second argument of
	prototype of export to const char *, and add reserverd int as
	third argument.  Add prototype for export_ext.
	* engine.c (_gpgme_engine_op_export_ext): New function.
	(_gpgme_engine_op_export): Change second argument of prototype of
	export to const char *, and add reserverd int as third argument.
	* rungpg.c (gpg_export): Change second argument of prototype of
	export to const char *, and add reserverd int as third argument.
	(gpg_export_ext): New function.
	(gpg_keylist_ext): Break loop at error.
	(_gpgme_engine_ops_gpg): Add gpg_export_ext.
	* engine-gpgsm.c (gpgsm_export): Change second argument of
	prototype of export to const char *, and add reserverd int as
	third argument.
	(gpgsm_export_ext): New function.
	(_gpgme_engine_ops_gpgsm): Add gpgsm_export_ext.
	* export.c (export_start): Change second argument of prototype of
	export to const char *, and add reserverd int as third argument.
	(gpgme_op_export_start): Likewise.
	(export_ext_start): New function.
	(gpgme_op_export_ext_start): Likewise.
	(gpgme_op_export_ext): Likewise.

	* gpgme.h (gpgme_keylist_mode_t): New type for anonymous enum.
	(gpgme_sigsum_t): New type for anonymous enum.

	* encrypt-sign.c (encrypt_sign_start): Check for errors earlier,
	and return an error if RECP is not set.

	* Makefile.am (libgpgme_la_SOURCES): Remove user-id.c.
	* user-id.c: Remove file.
	* ops.h: Remove prototype for _gpgme_user_ids_all_valid.
	* gpgme.h (gpgme_encrypt_flags_t): New type.
	(gpgme_op_encrypt_start): Change second parameter to type
	gpgme_key_t[], and add third parameter.
	(gpgme_op_encrypt): Likewise.
	(gpgme_op_encrypt_sign_start): Likewise.
	(gpgme_op_encrypt_sign): Likewise.
	* encrypt.c (encrypt_start): Likewise.
	(gpgme_op_encrypt_start): Likewise.
	(gpgme_op_encrypt): Likewise.  Pass flags to engine.
	* encrypt-sign.c (encrypt_sign_start): Likewise.
	(gpgme_op_encrypt_sign_start): Likewise.
	(gpgme_op_encrypt_sign): Likewise.
	* engine-backend.h (struct engine_ops): Likewise for prototypes of
	encrypt and encrypt_sign.
	* engine.h: Likewise for prototypes of _gpgme_engine_op_encrypt
	and _gpgme_engine_op_encrypt_sign.
	* engine.c (_gpgme_engine_op_encrypt): Likewise.
	(_gpgme_engine_op_encrypt_sign): Likewise.
	* rungpg.c (gpg_encrypt): Likewise.
	(gpg_encrypt_sign): Likewise.
	* rungpg.c (gpg_encrypt): Check flags for always trust option.
	* engine-gpgsm.c (gpgsm_encrypt): Likewise.
	(set_recipients): Rewritten to use keys instead user IDs.
	* rungpg.c (append_args_from_recipients): Rewritten to use keys
	instead user IDs.
	* encrypt.c (_gpgme_encrypt_status_handler): Change errors
	returned to GPGME_Invalid_Key and GPGME_General_Error.

tests/
2003-05-29  Marcus Brinkmann  <marcus@g10code.de>

	* gpg/t-encrypt-sym.c (main): Adapt to new syntax.
	* gpg/t-encrypt.c (main): Likewise.
	* gpg/t-eventloop.c (main): Likewise.
	* gpg/t-encrypt-sign.c (main): Likewise.
	* gpgsm/t-export.c (main): Likewise.
	* gpgsm/t-encrypt.c (main): Likewise.
2003-05-29 03:21:02 +00:00

480 lines
11 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* engine.c - GPGME engine support.
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2002, 2003 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPGME; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "gpgme.h"
#include "util.h"
#include "sema.h"
#include "ops.h"
#include "engine.h"
#include "engine-backend.h"
struct engine
{
struct engine_ops *ops;
void *engine;
};
static struct engine_ops *engine_ops[] =
{
&_gpgme_engine_ops_gpg, /* OpenPGP. */
#ifdef ENABLE_GPGSM
&_gpgme_engine_ops_gpgsm /* CMS. */
#else
NULL
#endif
};
/* Get the file name of the engine for PROTOCOL. */
static const char *
engine_get_file_name (gpgme_protocol_t proto)
{
if (proto > DIM (engine_ops))
return NULL;
if (engine_ops[proto] && engine_ops[proto]->get_file_name)
return (*engine_ops[proto]->get_file_name) ();
else
return NULL;
}
/* Get the version number of the engine for PROTOCOL. */
static const char *
engine_get_version (gpgme_protocol_t proto)
{
if (proto > DIM (engine_ops))
return NULL;
if (engine_ops[proto] && engine_ops[proto]->get_version)
return (*engine_ops[proto]->get_version) ();
else
return NULL;
}
/* Get the required version number of the engine for PROTOCOL. */
static const char *
engine_get_req_version (gpgme_protocol_t proto)
{
if (proto > DIM (engine_ops))
return NULL;
if (engine_ops[proto] && engine_ops[proto]->get_req_version)
return (*engine_ops[proto]->get_req_version) ();
else
return NULL;
}
/* Verify the version requirement for the engine for PROTOCOL. */
gpgme_error_t
gpgme_engine_check_version (gpgme_protocol_t proto)
{
return _gpgme_compare_versions (engine_get_version (proto),
engine_get_req_version (proto))
? 0 : GPGME_Invalid_Engine;
}
/* Get the information about the configured and installed engines. A
pointer to the first engine in the statically allocated linked list
is returned in *INFO. If an error occurs, it is returned. */
gpgme_error_t
gpgme_get_engine_info (gpgme_engine_info_t *info)
{
static gpgme_engine_info_t engine_info;
DEFINE_STATIC_LOCK (engine_info_lock);
LOCK (engine_info_lock);
if (!engine_info)
{
gpgme_engine_info_t *lastp = &engine_info;
gpgme_protocol_t proto_list[] = { GPGME_PROTOCOL_OpenPGP,
GPGME_PROTOCOL_CMS };
int proto;
for (proto = 0; proto < DIM (proto_list); proto++)
{
const char *file_name = engine_get_file_name (proto_list[proto]);
if (!file_name)
continue;
*lastp = malloc (sizeof (*engine_info));
if (!*lastp)
{
while (engine_info)
{
gpgme_engine_info_t next_info = engine_info->next;
free (engine_info);
engine_info = next_info;
}
UNLOCK (engine_info_lock);
return GPGME_Out_Of_Core;
}
(*lastp)->protocol = proto_list[proto];
(*lastp)->file_name = file_name;
(*lastp)->version = engine_get_version (proto_list[proto]);
(*lastp)->req_version = engine_get_req_version (proto_list[proto]);
lastp = &(*lastp)->next;
}
}
UNLOCK (engine_info_lock);
*info = engine_info;
return 0;
}
gpgme_error_t
_gpgme_engine_new (gpgme_protocol_t proto, engine_t *r_engine)
{
engine_t engine;
const char *file_name;
const char *version;
if (proto > DIM (engine_ops))
return GPGME_Invalid_Value;
if (!engine_ops[proto])
return GPGME_Invalid_Engine;
file_name = engine_get_file_name (proto);
version = engine_get_version (proto);
if (!file_name || !version)
return GPGME_Invalid_Engine;
engine = calloc (1, sizeof *engine);
if (!engine)
return GPGME_Out_Of_Core;
engine->ops = engine_ops[proto];
if (engine_ops[proto]->new)
{
gpgme_error_t err = (*engine_ops[proto]->new) (&engine->engine);
if (err)
{
free (engine);
return err;
}
}
else
engine->engine = NULL;
*r_engine = engine;
return 0;
}
void
_gpgme_engine_release (engine_t engine)
{
if (!engine)
return;
if (engine->ops->release)
(*engine->ops->release) (engine->engine);
free (engine);
}
void
_gpgme_engine_set_status_handler (engine_t engine,
engine_status_handler_t fnc, void *fnc_value)
{
if (!engine)
return;
if (engine->ops->set_status_handler)
(*engine->ops->set_status_handler) (engine->engine, fnc, fnc_value);
}
gpgme_error_t
_gpgme_engine_set_command_handler (engine_t engine,
engine_command_handler_t fnc,
void *fnc_value,
gpgme_data_t linked_data)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->set_command_handler)
return GPGME_Not_Implemented;
return (*engine->ops->set_command_handler) (engine->engine,
fnc, fnc_value, linked_data);
}
gpgme_error_t
_gpgme_engine_set_colon_line_handler (engine_t engine,
engine_colon_line_handler_t fnc,
void *fnc_value)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->set_colon_line_handler)
return GPGME_Not_Implemented;
return (*engine->ops->set_colon_line_handler) (engine->engine,
fnc, fnc_value);
}
gpgme_error_t
_gpgme_engine_op_decrypt (engine_t engine, gpgme_data_t ciph,
gpgme_data_t plain)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->decrypt)
return GPGME_Not_Implemented;
return (*engine->ops->decrypt) (engine->engine, ciph, plain);
}
gpgme_error_t
_gpgme_engine_op_delete (engine_t engine, gpgme_key_t key,
int allow_secret)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->delete)
return GPGME_Not_Implemented;
return (*engine->ops->delete) (engine->engine, key, allow_secret);
}
gpgme_error_t
_gpgme_engine_op_edit (engine_t engine, gpgme_key_t key, gpgme_data_t out,
gpgme_ctx_t ctx /* FIXME */)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->edit)
return GPGME_Not_Implemented;
return (*engine->ops->edit) (engine->engine, key, out, ctx);
}
gpgme_error_t
_gpgme_engine_op_encrypt (engine_t engine, gpgme_key_t recp[],
gpgme_encrypt_flags_t flags,
gpgme_data_t plain, gpgme_data_t ciph, int use_armor)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->encrypt)
return GPGME_Not_Implemented;
return (*engine->ops->encrypt) (engine->engine, recp, flags, plain, ciph,
use_armor);
}
gpgme_error_t
_gpgme_engine_op_encrypt_sign (engine_t engine, gpgme_key_t recp[],
gpgme_encrypt_flags_t flags,
gpgme_data_t plain, gpgme_data_t ciph,
int use_armor, gpgme_ctx_t ctx /* FIXME */)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->encrypt_sign)
return GPGME_Not_Implemented;
return (*engine->ops->encrypt_sign) (engine->engine, recp, flags,
plain, ciph, use_armor, ctx);
}
gpgme_error_t
_gpgme_engine_op_export (engine_t engine, const char *pattern,
unsigned int reserved, gpgme_data_t keydata,
int use_armor)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->export)
return GPGME_Not_Implemented;
return (*engine->ops->export) (engine->engine, pattern, reserved,
keydata, use_armor);
}
gpgme_error_t
_gpgme_engine_op_export_ext (engine_t engine, const char *pattern[],
unsigned int reserved, gpgme_data_t keydata,
int use_armor)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->export_ext)
return GPGME_Not_Implemented;
return (*engine->ops->export_ext) (engine->engine, pattern, reserved,
keydata, use_armor);
}
gpgme_error_t
_gpgme_engine_op_genkey (engine_t engine, gpgme_data_t help_data,
int use_armor, gpgme_data_t pubkey,
gpgme_data_t seckey)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->genkey)
return GPGME_Not_Implemented;
return (*engine->ops->genkey) (engine->engine, help_data, use_armor,
pubkey, seckey);
}
gpgme_error_t
_gpgme_engine_op_import (engine_t engine, gpgme_data_t keydata)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->import)
return GPGME_Not_Implemented;
return (*engine->ops->import) (engine->engine, keydata);
}
gpgme_error_t
_gpgme_engine_op_keylist (engine_t engine, const char *pattern,
int secret_only, gpgme_keylist_mode_t mode)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->keylist)
return GPGME_Not_Implemented;
return (*engine->ops->keylist) (engine->engine, pattern, secret_only, mode);
}
gpgme_error_t
_gpgme_engine_op_keylist_ext (engine_t engine, const char *pattern[],
int secret_only, int reserved,
gpgme_keylist_mode_t mode)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->keylist_ext)
return GPGME_Not_Implemented;
return (*engine->ops->keylist_ext) (engine->engine, pattern, secret_only,
reserved, mode);
}
gpgme_error_t
_gpgme_engine_op_sign (engine_t engine, gpgme_data_t in, gpgme_data_t out,
gpgme_sig_mode_t mode, int use_armor,
int use_textmode, int include_certs,
gpgme_ctx_t ctx /* FIXME */)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->sign)
return GPGME_Not_Implemented;
return (*engine->ops->sign) (engine->engine, in, out, mode, use_armor,
use_textmode, include_certs, ctx);
}
gpgme_error_t
_gpgme_engine_op_trustlist (engine_t engine, const char *pattern)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->trustlist)
return GPGME_Not_Implemented;
return (*engine->ops->trustlist) (engine->engine, pattern);
}
gpgme_error_t
_gpgme_engine_op_verify (engine_t engine, gpgme_data_t sig,
gpgme_data_t signed_text, gpgme_data_t plaintext)
{
if (!engine)
return GPGME_Invalid_Value;
if (!engine->ops->verify)
return GPGME_Not_Implemented;
return (*engine->ops->verify) (engine->engine, sig, signed_text, plaintext);
}
void
_gpgme_engine_set_io_cbs (engine_t engine, gpgme_io_cbs_t io_cbs)
{
if (!engine)
return;
(*engine->ops->set_io_cbs) (engine->engine, io_cbs);
}
void
_gpgme_engine_io_event (engine_t engine,
gpgme_event_io_t type, void *type_data)
{
if (!engine)
return;
(*engine->ops->io_event) (engine->engine, type, type_data);
}