2003-04-25 Marcus Brinkmann <marcus@g10code.de>
* edit.c: Do not include <assert.h>, "util.h", but "gpgme.h". (edit_resut): Change to typedef for op_data_t. (edit_status_handler): Change first argument to void *. Rework error handling. (command_handler): Rework error handling. (_gpgme_op_edit_start): Rename to ... (edit_start): ... this. Rework error handling. (gpgme_op_edit_start): Rewrite using edit_start. (gpgme_op_edit): Likewise.
This commit is contained in:
parent
8002f98d48
commit
cceb2cc292
@ -1,5 +1,15 @@
|
|||||||
2003-04-25 Marcus Brinkmann <marcus@g10code.de>
|
2003-04-25 Marcus Brinkmann <marcus@g10code.de>
|
||||||
|
|
||||||
|
* edit.c: Do not include <assert.h>, "util.h", but "gpgme.h".
|
||||||
|
(edit_resut): Change to typedef for op_data_t.
|
||||||
|
(edit_status_handler): Change first argument to void *.
|
||||||
|
Rework error handling.
|
||||||
|
(command_handler): Rework error handling.
|
||||||
|
(_gpgme_op_edit_start): Rename to ...
|
||||||
|
(edit_start): ... this. Rework error handling.
|
||||||
|
(gpgme_op_edit_start): Rewrite using edit_start.
|
||||||
|
(gpgme_op_edit): Likewise.
|
||||||
|
|
||||||
* ops.h (_gpgme_passphrase_start): Remove prototype.
|
* ops.h (_gpgme_passphrase_start): Remove prototype.
|
||||||
* passphrase.c: Do not include <assert.h>, "util.h" or
|
* passphrase.c: Do not include <assert.h>, "util.h" or
|
||||||
"debug.h", but "gpgme.h".
|
"debug.h", but "gpgme.h".
|
||||||
|
148
gpgme/edit.c
148
gpgme/edit.c
@ -1,4 +1,4 @@
|
|||||||
/* edit.c - Key edit functions.
|
/* edit.c - Key edit function.
|
||||||
Copyright (C) 2002, 2003 g10 Code GmbH
|
Copyright (C) 2002, 2003 g10 Code GmbH
|
||||||
|
|
||||||
This file is part of GPGME.
|
This file is part of GPGME.
|
||||||
@ -21,143 +21,109 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "util.h"
|
#include "gpgme.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "ops.h"
|
#include "ops.h"
|
||||||
|
|
||||||
|
|
||||||
struct edit_result
|
typedef struct
|
||||||
{
|
{
|
||||||
|
/* The user callback function and its hook value. */
|
||||||
GpgmeEditCb fnc;
|
GpgmeEditCb fnc;
|
||||||
void *fnc_value;
|
void *fnc_value;
|
||||||
};
|
} *op_data_t;
|
||||||
typedef struct edit_result *EditResult;
|
|
||||||
|
|
||||||
|
|
||||||
static GpgmeError
|
static GpgmeError
|
||||||
edit_status_handler (GpgmeCtx ctx, GpgmeStatusCode status, char *args)
|
edit_status_handler (void *priv, GpgmeStatusCode status, char *args)
|
||||||
{
|
{
|
||||||
EditResult result;
|
GpgmeCtx ctx = (GpgmeCtx) priv;
|
||||||
GpgmeError err = _gpgme_passphrase_status_handler (ctx, status, args);
|
op_data_t opd;
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
err = _gpgme_progress_status_handler (ctx, status, args);
|
return _gpgme_passphrase_status_handler (priv, status, args)
|
||||||
if (err)
|
|| _gpgme_progress_status_handler (priv, status, args)
|
||||||
return err;
|
|| _gpgme_op_data_lookup (ctx, OPDATA_EDIT, (void **) &opd, -1, NULL)
|
||||||
|
|| (*opd->fnc) (opd->fnc_value, status, args, NULL);
|
||||||
err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, (void **) &result,
|
|
||||||
-1, NULL);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
assert (result);
|
|
||||||
|
|
||||||
return (*result->fnc) (result->fnc_value, status, args, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static GpgmeError
|
static GpgmeError
|
||||||
command_handler (void *opaque, GpgmeStatusCode status, const char *args,
|
command_handler (void *priv, GpgmeStatusCode status, const char *args,
|
||||||
const char **result_r)
|
const char **result)
|
||||||
{
|
{
|
||||||
EditResult result;
|
GpgmeCtx ctx = (GpgmeCtx) priv;
|
||||||
GpgmeError err;
|
GpgmeError err;
|
||||||
GpgmeCtx ctx = opaque;
|
op_data_t opd;
|
||||||
|
|
||||||
*result_r = NULL;
|
*result = NULL;
|
||||||
err = _gpgme_passphrase_command_handler (ctx, status, args, result_r);
|
if (ctx->passphrase_cb)
|
||||||
|
{
|
||||||
|
err = _gpgme_passphrase_command_handler (ctx, status, args, result);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!*result)
|
||||||
|
{
|
||||||
|
err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, (void **) &opd, -1, NULL);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, (void **) &result,
|
return (*opd->fnc) (opd->fnc_value, status, args, result);
|
||||||
-1, NULL);
|
}
|
||||||
if (err)
|
return 0;
|
||||||
return err;
|
|
||||||
assert (result);
|
|
||||||
|
|
||||||
if (!*result_r)
|
|
||||||
err = (*result->fnc) (result->fnc_value, status, args, result_r);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static GpgmeError
|
static GpgmeError
|
||||||
_gpgme_op_edit_start (GpgmeCtx ctx, int synchronous,
|
edit_start (GpgmeCtx ctx, int synchronous, GpgmeKey key,
|
||||||
GpgmeKey key,
|
GpgmeEditCb fnc, void *fnc_value, GpgmeData out)
|
||||||
GpgmeEditCb fnc, void *fnc_value,
|
|
||||||
GpgmeData out)
|
|
||||||
{
|
{
|
||||||
EditResult result;
|
GpgmeError err;
|
||||||
GpgmeError err = 0;
|
op_data_t opd;
|
||||||
|
|
||||||
if (!fnc)
|
|
||||||
return GPGME_Invalid_Value;
|
|
||||||
|
|
||||||
err = _gpgme_op_reset (ctx, synchronous);
|
err = _gpgme_op_reset (ctx, synchronous);
|
||||||
if (err)
|
if (err)
|
||||||
goto leave;
|
return err;
|
||||||
|
|
||||||
err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, (void **) &result,
|
if (!fnc || !out)
|
||||||
sizeof (*result), NULL);
|
return GPGME_Invalid_Value;
|
||||||
|
|
||||||
|
err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, (void **) &opd,
|
||||||
|
sizeof (*opd), NULL);
|
||||||
if (err)
|
if (err)
|
||||||
goto leave;
|
return err;
|
||||||
|
|
||||||
result->fnc = fnc;
|
opd->fnc = fnc;
|
||||||
result->fnc_value = fnc_value;
|
opd->fnc_value = fnc_value;
|
||||||
|
|
||||||
/* Check the supplied data. */
|
|
||||||
if (!out)
|
|
||||||
{
|
|
||||||
err = GPGME_Invalid_Value;
|
|
||||||
goto leave;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = _gpgme_engine_set_command_handler (ctx->engine, command_handler,
|
err = _gpgme_engine_set_command_handler (ctx->engine, command_handler,
|
||||||
ctx, out);
|
ctx, out);
|
||||||
if (err)
|
if (err)
|
||||||
goto leave;
|
return err;
|
||||||
|
|
||||||
_gpgme_engine_set_status_handler (ctx->engine, edit_status_handler, ctx);
|
_gpgme_engine_set_status_handler (ctx->engine, edit_status_handler, ctx);
|
||||||
|
|
||||||
err = _gpgme_engine_op_edit (ctx->engine, key, out, ctx);
|
return _gpgme_engine_op_edit (ctx->engine, key, out, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
leave:
|
|
||||||
if (err)
|
|
||||||
{
|
|
||||||
_gpgme_engine_release (ctx->engine);
|
|
||||||
ctx->engine = NULL;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
GpgmeError
|
GpgmeError
|
||||||
gpgme_op_edit_start (GpgmeCtx ctx,
|
gpgme_op_edit_start (GpgmeCtx ctx, GpgmeKey key,
|
||||||
GpgmeKey key,
|
GpgmeEditCb fnc, void *fnc_value, GpgmeData out)
|
||||||
GpgmeEditCb fnc, void *fnc_value,
|
|
||||||
GpgmeData out)
|
|
||||||
{
|
{
|
||||||
return _gpgme_op_edit_start (ctx, 0, key, fnc, fnc_value, out);
|
return edit_start (ctx, 0, key, fnc, fnc_value, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* gpgme_op_edit:
|
/* Edit the key KEY. Send status and command requests to FNC and
|
||||||
* @ctx: The context
|
output of edit commands to OUT. */
|
||||||
* @key: The key to be edited.
|
|
||||||
* @fnc: An edit callback handler.
|
|
||||||
* @fnc_value: To be passed to @fnc as first arg.
|
|
||||||
* @out: The output.
|
|
||||||
*
|
|
||||||
* Return value: 0 on success or an error code.
|
|
||||||
**/
|
|
||||||
GpgmeError
|
GpgmeError
|
||||||
gpgme_op_edit (GpgmeCtx ctx,
|
gpgme_op_edit (GpgmeCtx ctx, GpgmeKey key,
|
||||||
GpgmeKey key,
|
GpgmeEditCb fnc, void *fnc_value, GpgmeData out)
|
||||||
GpgmeEditCb fnc, void *fnc_value,
|
|
||||||
GpgmeData out)
|
|
||||||
{
|
{
|
||||||
GpgmeError err = _gpgme_op_edit_start (ctx, 1, key, fnc, fnc_value, out);
|
GpgmeError err = edit_start (ctx, 1, key, fnc, fnc_value, out);
|
||||||
if (!err)
|
if (!err)
|
||||||
err = _gpgme_wait_one (ctx);
|
err = _gpgme_wait_one (ctx);
|
||||||
return err;
|
return err;
|
||||||
|
Loading…
Reference in New Issue
Block a user