gpgme/gpgme/op-support.c
Marcus Brinkmann 2971894b27 doc/
2003-04-27  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.texi (Creating a Signature): Add info about
	GpgmeNewSignature, GpgmeSignResult and gpgme_op_sign_result.
	(Crypto Operations): Add GpgmeInvalidUserID.
	(Algorithms): New chapter.

gpgme/
2003-04-27  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.h (GpgmePubKeyAlgo, GpgmeHashAlgo, GpgmeInvalidUserID,
	GpgmeNewSignature, GpgmeSignResult): New data types.
	(gpgme_op_sign_result, gpgme_pubkey_algo_name,
	gpgme_hash_algo_name): New prototypes.
	* gpgme.c (gpgme_pubkey_algo_name): New function.
	(gpgme_hash_algo_name): Likewise.
	* ops.h (_gpgme_parse_inv_userid, _gpgme_op_sign_init_result): New
	prototype.
	(_gpgme_op_sign_status_handler): Fix prototype.
	* op-support.c: Include <errno.h> and <string.h>.
	(_gpgme_parse_inv_userid): New function.
	* sign.c: Include <errno.h> and "gpgme.h", but not <stdio.h>,
	<assert.h> and "util.h".
	(SKIP_TOKEN_OR_RETURN): Remove macro.
	(struct sign_result): Change to op_data_t type and rework it.
	(release_sign_result): Rename to ...
	(release_op_data): ... this and rewrite it.
	(append_xml_info): Remove function.
	(gpgme_op_sign_result): New function.
	(parse_sig_created): New function.
	(_gpgme_sign_status_handler): Change first argument to void *.
	Rewrite the function to use the new result structure and functions.
	(_gpgme_op_sign_init_result): New function.
	(_gpgme_op_sign_start): Rename to ...
	(sign_start): ... this.  Call _gpgme_op_sign_init_result.
	(gpgme_op_sign_start): Use sign_start instead _gpgme_op_sign_start.
	(gpgme_op_sign): Likewise.
2003-04-27 20:53:04 +00:00

186 lines
4.4 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.

/* op-support.c
Copyright (C) 2002, 2003 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPGME; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "gpgme.h"
#include "context.h"
#include "ops.h"
GpgmeError
_gpgme_op_data_lookup (GpgmeCtx ctx, ctx_op_data_type type, void **hook,
int size, void (*cleanup) (void *))
{
struct ctx_op_data *data = ctx->op_data;
while (data && data->type != type)
data = data->next;
if (!data)
{
if (size < 0)
{
*hook = NULL;
return 0;
}
data = calloc (1, sizeof (struct ctx_op_data) + size);
if (!data)
return GPGME_Out_Of_Core;
data->next = ctx->op_data;
data->type = type;
data->cleanup = cleanup;
data->hook = ((void *) data) + sizeof (struct ctx_op_data);
ctx->op_data = data;
}
*hook = data->hook;
return 0;
}
/* type is: 0: asynchronous operation (use global or user event loop).
1: synchronous operation (always use private event loop).
2: asynchronous private operation (use private or user
event loop). */
GpgmeError
_gpgme_op_reset (GpgmeCtx ctx, int type)
{
GpgmeError err = 0;
struct GpgmeIOCbs io_cbs;
_gpgme_release_result (ctx);
/* Create an engine object. */
_gpgme_engine_release (ctx->engine);
ctx->engine = NULL;
err = _gpgme_engine_new (ctx->protocol, &ctx->engine);
if (err)
return err;
if (type == 1 || (type == 2 && !ctx->io_cbs.add))
{
/* Use private event loop. */
io_cbs.add = _gpgme_add_io_cb;
io_cbs.add_priv = ctx;
io_cbs.remove = _gpgme_remove_io_cb;
io_cbs.event = _gpgme_wait_private_event_cb;
io_cbs.event_priv = ctx;
}
else if (! ctx->io_cbs.add)
{
/* Use global event loop. */
io_cbs.add = _gpgme_add_io_cb;
io_cbs.add_priv = ctx;
io_cbs.remove = _gpgme_remove_io_cb;
io_cbs.event = _gpgme_wait_global_event_cb;
io_cbs.event_priv = ctx;
}
else
{
/* Use user event loop. */
io_cbs.add = _gpgme_wait_user_add_io_cb;
io_cbs.add_priv = ctx;
io_cbs.remove = _gpgme_wait_user_remove_io_cb;
io_cbs.event = _gpgme_wait_user_event_cb;
io_cbs.event_priv = ctx;
}
_gpgme_engine_set_io_cbs (ctx->engine, &io_cbs);
return err;
}
GpgmeError
_gpgme_parse_inv_userid (char *args, GpgmeInvalidUserID *userid)
{
GpgmeInvalidUserID inv_userid;
char *tail;
long int reason;
inv_userid = malloc (sizeof (*inv_userid));
if (!inv_userid)
return GPGME_Out_Of_Core;
inv_userid->next = NULL;
errno = 0;
reason = strtol (args, &tail, 0);
if (errno || args == tail || *tail != ' ')
{
/* The crypto backend does not behave. */
free (inv_userid);
return GPGME_General_Error;
}
switch (reason)
{
default:
case 0:
inv_userid->reason = GPGME_Unknown_Reason;
case 1:
inv_userid->reason = GPGME_Not_Found;
case 2:
inv_userid->reason = GPGME_Ambiguous_Specification;
case 3:
inv_userid->reason = GPGME_Wrong_Key_Usage;
case 4:
inv_userid->reason = GPGME_Key_Revoked;
case 5:
inv_userid->reason = GPGME_Key_Expired;
case 6:
inv_userid->reason = GPGME_No_CRL_Known;
case 7:
inv_userid->reason = GPGME_CRL_Too_Old;
case 8:
inv_userid->reason = GPGME_Policy_Mismatch;
case 9:
inv_userid->reason = GPGME_No_Secret_Key;
case 10:
inv_userid->reason = GPGME_Key_Not_Trusted;
}
while (*tail == ' ')
tail++;
if (*tail)
{
inv_userid->id = strdup (tail);
if (!inv_userid->id)
{
free (inv_userid);
return GPGME_Out_Of_Core;
}
}
else
inv_userid->id = NULL;
*userid = inv_userid;
return 0;
}