gpgme/trunk/gpgme/passphrase.c
Marcus Brinkmann 16dd11f481 2003-05-18 Marcus Brinkmann <marcus@g10code.de>
In all files, replace the Gpgme* type names with the new gpgme_*
	type names.

doc/
2003-05-18  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.texi (Header): Remove Gpgme as namespace prefix.  Add
	_GPGME to namespace prefix.
	* gpgme.texi (Multi Threading): Add note about link order.

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

	* gpgme.h: The following types are renamed.  The old name is kept
	as a deprecated typedef.
	(GpgmeCtx): Rename to gpgme_ctx_t.
	(GpgmeData): Rename to gpgme_data_t.
	(GpgmeRecipients): Rename to gpgme_recipients_t.
	(GpgmeError): Rename to gpgme_error_t.
	(GpgmeDataEncoding): Rename to gpgme_data_encoding_t.
	(GpgmePubKeyAlgo): Rename to gpgme_pubkey_algo_t.
	(GpgmeHashAlgo): Rename to gpgme_hash_algo_t.
	(GpgmeSigStat): Rename to gpgme_sig_stat_t.
	(GpgmeSigMode): Rename to gpgme_sig_mode_t.
	(GpgmeAttr): Rename to gpgme_attr_t.
	(GpgmeValidity): Rename to gpgme_validity_t.
	(GpgmeProtocol): Rename to gpgme_protocol_t.
	(GpgmeStatusCode): Rename to gpgme_status_code_t.
	(GpgmeEngineInfo): Rename to gpgme_engine_info_t.
	(GpgmeSubkey): Rename to gpgme_subkey_t.
	(GpgmeKeySig): Rename to gpgme_keysig_t.
	(GpgmeUserID): Rename to gpgme_user_id_t.
	(GpgmePassphraseCb): Rename to gpgme_passphrase_cb_t.
	(GpgmeProgressCb): Rename to gpgme_progress_cb_t.
	(GpgmeEditCb): Rename to gpgme_edit_cb_t.
	(GpgmeIOCb): Rename to gpgme_io_cb_t.
	(GpgmeRegisterIOCb): Rename to gpgme_register_io_cb_t.
	(GpgmeRemoveIOCb): Rename to gpgme_remove_io_cb_t.
	(GpgmeEventIO): Rename to gpgme_event_io_t.
	(GpgmeEventIOCb): Rename to gpgme_event_io_cb_t.
	(GpgmeIOCbs): Rename to gpgme_io_cbs.
	(gpgme_io_cbs_t): New type.
	(GpgmeDataReadCb): Rename to gpgme_data_read_cb_t.
	(GpgmeDataWriteCb): Rename to gpgme_data_write_cb_t.
	(GpgmeDataSeekCb): Rename to gpgme_data_seek_cb_t.
	(GpgmeDataReleaseCb): Rename to gpgme_data_release_cb_t.
	(GpgmeDataCbs): Rename to gpgme_data_cbs.
	(gpgme_data_cbs_t): New type.
	(GpgmeInvalidUserID): Rename to gpgme_invalid_user_id_t.
	(GpgmeEncryptResult): Rename to gpgme_encrypt_result_t.
	(GpgmeDecryptResult): Rename to gpgme_decrypt_result_t.
	(GpgmeNewSignature): Rename to gpgme_new_signature_t.
	(GpgmeSignResult): Rename to gpgme_sign_result_t.
	(GpgmeSigNotation): Rename to gpgme_sig_notation_t.
	(GpgmeSignature): Rename to gpgme_signature_t.
	(GpgmeVerifyResult): Rename to gpgme_verify_result_t.
	(GpgmeImportStatus): Rename to gpgme_import_status_t.
	(GpgmeImportResult): Rename to gpgme_import_result_t.
	(GpgmeGenKeyResult): Rename to gpgme_genkey_result_t.
	(GpgmeKeyListResult): Rename to gpgme_keylist_result_t.
	(GpgmeTrustItem): Rename to gpgme_trust_item_t.
	* gpgme.h (gpgme_deprecated_error_t): New type, swallowing macros
	GPGME_No_Recipients, GPGME_Invalid_Recipient and
	GPGME_No_Passphrase.
	* data.h (struct gpgme_data_s): Rename to struct gpgme_data.
	* context.h (struct gpgme_context_s): Rename to struct
	gpgme_context.
	(struct gpgme_recipients_s): Rename to gpgme_recipients.
2003-05-18 20:45:24 +00:00

175 lines
4.2 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.

/* passphrase.c - Passphrase callback.
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. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gpgme.h"
#include "context.h"
#include "ops.h"
typedef struct
{
int no_passphrase;
void *last_pw_handle;
char *userid_hint;
char *passphrase_info;
int bad_passphrase;
} *op_data_t;
static void
release_op_data (void *hook)
{
op_data_t opd = (op_data_t) hook;
free (opd->passphrase_info);
free (opd->userid_hint);
}
gpgme_error_t
_gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code, char *args)
{
gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
gpgme_error_t err;
op_data_t opd;
if (!ctx->passphrase_cb)
return 0;
err = _gpgme_op_data_lookup (ctx, OPDATA_PASSPHRASE, (void **) &opd,
sizeof (*opd), release_op_data);
if (err)
return err;
switch (code)
{
case GPGME_STATUS_USERID_HINT:
if (opd->userid_hint)
free (opd->userid_hint);
if (!(opd->userid_hint = strdup (args)))
return GPGME_Out_Of_Core;
break;
case GPGME_STATUS_BAD_PASSPHRASE:
opd->bad_passphrase++;
opd->no_passphrase = 0;
break;
case GPGME_STATUS_GOOD_PASSPHRASE:
opd->bad_passphrase = 0;
opd->no_passphrase = 0;
break;
case GPGME_STATUS_NEED_PASSPHRASE:
case GPGME_STATUS_NEED_PASSPHRASE_SYM:
if (opd->passphrase_info)
free (opd->passphrase_info);
opd->passphrase_info = strdup (args);
if (!opd->passphrase_info)
return GPGME_Out_Of_Core;
break;
case GPGME_STATUS_MISSING_PASSPHRASE:
opd->no_passphrase = 1;
break;
case GPGME_STATUS_EOF:
if (opd->no_passphrase || opd->bad_passphrase)
return GPGME_Bad_Passphrase;
break;
default:
/* Ignore all other codes. */
break;
}
return 0;
}
gpgme_error_t
_gpgme_passphrase_command_handler (void *priv, gpgme_status_code_t code,
const char *key, const char **result)
{
gpgme_ctx_t ctx = (gpgme_ctx_t) priv;
gpgme_error_t err;
op_data_t opd;
if (!ctx->passphrase_cb)
return 0;
err = _gpgme_op_data_lookup (ctx, OPDATA_PASSPHRASE, (void **) &opd,
sizeof (*opd), release_op_data);
if (err)
return err;
if (!code)
{
/* We have been called for cleanup. */
if (ctx->passphrase_cb)
/* FIXME: Take the key in account. */
err = ctx->passphrase_cb (ctx->passphrase_cb_value, NULL,
&opd->last_pw_handle, NULL);
*result = NULL;
return err;
}
if (!key || !ctx->passphrase_cb)
{
*result = NULL;
return 0;
}
if (code == GPGME_STATUS_GET_HIDDEN && !strcmp (key, "passphrase.enter"))
{
const char *userid_hint = opd->userid_hint;
const char *passphrase_info = opd->passphrase_info;
int bad_passphrase = opd->bad_passphrase;
char *buf;
opd->bad_passphrase = 0;
if (!userid_hint)
userid_hint = "[User ID hint missing]";
if (!passphrase_info)
passphrase_info = "[passphrase info missing]";
buf = malloc (20 + strlen (userid_hint)
+ strlen (passphrase_info) + 3);
if (!buf)
return GPGME_Out_Of_Core;
sprintf (buf, "%s\n%s\n%s",
bad_passphrase ? "TRY_AGAIN":"ENTER",
userid_hint, passphrase_info);
err = ctx->passphrase_cb (ctx->passphrase_cb_value, buf,
&opd->last_pw_handle, result);
free (buf);
return err;
}
*result = NULL;
return 0;
}