2000-10-27 14:55:24 +00:00
|
|
|
/* gpgme.c - GnuPG Made Easy
|
|
|
|
* Copyright (C) 2000 Werner Koch (dd9jn)
|
2002-01-15 19:58:41 +00:00
|
|
|
* Copyright (C) 2001, 2002 g10 Code GmbH
|
2000-10-27 14:55:24 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-11-15 21:32:09 +00:00
|
|
|
#include <string.h>
|
2000-12-06 12:17:10 +00:00
|
|
|
#include <assert.h>
|
2000-10-27 14:55:24 +00:00
|
|
|
|
2000-11-07 13:32:38 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "context.h"
|
2000-11-09 16:35:35 +00:00
|
|
|
#include "ops.h"
|
2000-10-27 14:55:24 +00:00
|
|
|
|
2002-02-25 18:31:07 +00:00
|
|
|
|
2000-11-07 13:32:38 +00:00
|
|
|
/**
|
2000-11-13 13:25:22 +00:00
|
|
|
* gpgme_new:
|
2000-11-07 13:32:38 +00:00
|
|
|
* @r_ctx: Returns the new context
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2000-11-07 13:32:38 +00:00
|
|
|
* Create a new context to be used with most of the other GPGME
|
2002-01-31 00:31:44 +00:00
|
|
|
* functions. Use gpgme_release_context() to release all resources
|
2000-11-07 13:32:38 +00:00
|
|
|
*
|
2002-02-27 20:59:20 +00:00
|
|
|
* Return value: An error code
|
2000-11-07 13:32:38 +00:00
|
|
|
**/
|
|
|
|
GpgmeError
|
2000-11-13 13:25:22 +00:00
|
|
|
gpgme_new (GpgmeCtx *r_ctx)
|
2000-10-27 17:46:09 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
GpgmeCtx ctx;
|
2000-10-27 17:46:09 +00:00
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
if (!r_ctx)
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
*r_ctx = 0;
|
|
|
|
ctx = xtrycalloc (1, sizeof *ctx);
|
|
|
|
if (!ctx)
|
|
|
|
return mk_error (Out_Of_Core);
|
2002-02-06 00:08:47 +00:00
|
|
|
ctx->keylist_mode = GPGME_KEYLIST_MODE_LOCAL;
|
2002-01-15 19:58:41 +00:00
|
|
|
ctx->verbosity = 1;
|
2002-02-25 18:31:07 +00:00
|
|
|
ctx->include_certs = 1;
|
2002-01-15 19:58:41 +00:00
|
|
|
*r_ctx = ctx;
|
2000-12-12 13:31:25 +00:00
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
return 0;
|
2000-11-07 13:32:38 +00:00
|
|
|
}
|
2000-10-27 17:46:09 +00:00
|
|
|
|
2002-02-25 18:31:07 +00:00
|
|
|
|
2000-11-07 13:32:38 +00:00
|
|
|
/**
|
2000-11-13 13:25:22 +00:00
|
|
|
* gpgme_release:
|
2002-02-27 20:59:20 +00:00
|
|
|
* @c: Context to be released.
|
|
|
|
*
|
2000-11-07 13:32:38 +00:00
|
|
|
* Release all resources associated with the given context.
|
|
|
|
**/
|
|
|
|
void
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_release (GpgmeCtx ctx)
|
2000-11-07 13:32:38 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
if (!ctx)
|
2001-11-21 03:40:17 +00:00
|
|
|
return;
|
2002-02-27 20:59:20 +00:00
|
|
|
_gpgme_engine_release (ctx->engine);
|
2002-01-15 19:58:41 +00:00
|
|
|
_gpgme_release_result (ctx);
|
|
|
|
gpgme_key_release (ctx->tmp_key);
|
|
|
|
gpgme_data_release (ctx->help_data_1);
|
|
|
|
gpgme_data_release (ctx->notation);
|
|
|
|
gpgme_signers_clear (ctx);
|
|
|
|
if (ctx->signers)
|
|
|
|
xfree (ctx->signers);
|
2001-11-21 03:40:17 +00:00
|
|
|
/* FIXME: Release the key_queue. */
|
2002-01-15 19:58:41 +00:00
|
|
|
xfree (ctx);
|
2000-10-27 17:46:09 +00:00
|
|
|
}
|
2000-10-27 14:55:24 +00:00
|
|
|
|
2000-11-09 16:35:35 +00:00
|
|
|
void
|
2002-01-15 19:58:41 +00:00
|
|
|
_gpgme_release_result (GpgmeCtx ctx)
|
2000-11-09 16:35:35 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
_gpgme_release_verify_result (ctx->result.verify);
|
|
|
|
_gpgme_release_decrypt_result (ctx->result.decrypt);
|
|
|
|
_gpgme_release_sign_result (ctx->result.sign);
|
|
|
|
_gpgme_release_encrypt_result (ctx->result.encrypt);
|
|
|
|
_gpgme_release_passphrase_result (ctx->result.passphrase);
|
2002-01-30 21:52:32 +00:00
|
|
|
_gpgme_release_import_result (ctx->result.import);
|
2002-01-30 22:45:22 +00:00
|
|
|
_gpgme_release_delete_result (ctx->result.delete);
|
2002-01-31 00:31:44 +00:00
|
|
|
_gpgme_release_genkey_result (ctx->result.genkey);
|
2002-01-15 19:58:41 +00:00
|
|
|
memset (&ctx->result, 0, sizeof (ctx->result));
|
|
|
|
_gpgme_set_op_info (ctx, NULL);
|
2002-02-02 Marcus Brinkmann <marcus@g10code.de>
This patch has gotten a bit large... mmh. The main thing that
happens here is that error values are now not determined in the
operation function after gpgme_wait completed, but in the status
handler when EOF is received. It should always be the case that
either an error is flagged or EOF is received, so that after a
gpgme_wait you should never have the situation that no error is
flagged and EOF is not received. One problem is that the engine
status handlers don't have access to the context, a horrible
kludge works around this for now. All errors that happen during a
pending operation should be catched and reported in ctx->error,
including out-of-core and cancellation. This rounds up neatly a
couple of loose ends, and makes it possible to pass up any errors
in the communication with the backend as well. As a bonus, there
will be a function to access gpgme->wait, so that the operations
can truly be implemented with their _start function.
* engine-gpgsm.c (gpgsm_status_handler): Horrible kludge to report
error back to the context.
* rungpg.c (gpg_status_handler): Same horrible kludge applied here.
* engine-gpgsm.c (gpgsm_assuan_simple_command): Add error checking.
* wait.c (_gpgme_wait_on_condition): If canceled, set CTX->error
to a value indication that.
* verify.c (add_notation): Set error, not out_of_core.
(finish_sig): Likewise.
(gpgme_op_verify_start): Don't clear out_of_core.
(_gpgme_verify_status_handler): At EOF, clean up the notation data.
(gpgme_op_verify): And don't do it here.
* trustlist.c (trustlist_status_handler): Check error, not out_of_core.
(gpgme_op_trustlist_start): Don't clear out_of_core.
(gpgme_op_trustlist_next): Check error, not out_of_core.
(gpgme_op_trustlist_end): Likewise.
* ops.h (test_and_allocate_result): New macro.
(_gpgme_passphrase_result): Remove prototype.
* delete.c (gpgme_op_delete): Return error from context.
(delete_status_handler): Use macro test_and_allocate_result.
Perform error checking at EOF.
(gpgme_op_delete_start): Release result.
* passphrase.c (_gpgme_passphrase_status_handler): Use macro
test_and_allocate_result, and perform error checking here.
(_gpgme_passphrase_result): Function removed.
* sign.c (gpgme_op_sign_start): Do not set out_of_core to zero.
(gpgme_op_sign): Just return the error value from the context.
(sign_status_handler): Only progress if no error is set yet. If
we process an EOF, set the resulting error value (if any).
* decrypt.c (_gpgme_decrypt_result): Function removed.
(create_result_struct): Function removed.
(_gpgme_decrypt_status_handler): Use macro test_and_allocate_result,
caclulate error on EOF, do not progress with errors.
(_gpgme_decrypt_start): Do not set out_of_core to zero.
(gpgme_op_decrypt): Just return the error value from the context.
* encrypt.c (encrypt_status_handler): Perform the error checking
here.
(gpgme_op_encrypt_start): Do not clear out_of_core.
* export.c (export_status_handler): Return if error is set in context.
(gpgme_op_export_start): Release result.
(gpgme_op_export): Return error from context.
* decrypt-verify.c (gpgme_op_decrypt_verify): Return the error in
the context.
* genkey.c (genkey_status_handler): Use macro
test_and_allocate_result. Perform error checking at EOF.
(gpgme_op_genkey): Just return the error from context.
* import.c (gpgme_op_import): Return the error from context.
(import_status_handler): Use macro test_and_allocate_result.
* keylist.c (gpgme_op_keylist_start): Do not clear out_of_core.
(gpgme_op_keylist_next): Return error of context.
(keylist_colon_handler): Set error instead out_of_code.
(finish_key): Likewise.
* context.h: Remove member out_of_core, add member error.
* gpgme.c (_gpgme_release_result): Clear error flag.
* engine.h (_gpgme_engine_get_error): New prototype.
* engine.c (_gpgme_engine_get_error): New function.
* engine-gpgsm.c (_gpgme_gpgsm_get_error): New function.
* engine-gpgsm.c (map_assuan_error): New function.
(gpgsm_assuan_simple_command): Change return type to GpgmeError,
use the new function to map error values.
(gpgsm_set_fd): Change return type tp GpgmeError.
(_gpgme_gpgsm_op_decrypt): Change type of ERR to GpgmeError.
(gpgsm_set_recipients): Likewise. Change type of return value
equivalently. Adjust error values.
(_gpgme_gpgsm_op_import): Likewise.
(_gpgme_gpgsm_op_sign): Likewise.
(struct gpgsm_object_s): New member error.
(gpgsm_status_handler): Set error if error occurs. Determine
error number from ERR line received. If assuan_read_line fails,
terminate the connection.
2002-02-02 03:52:59 +00:00
|
|
|
ctx->error = 0;
|
2000-11-09 16:35:35 +00:00
|
|
|
}
|
2000-11-07 13:32:38 +00:00
|
|
|
|
|
|
|
|
2000-12-29 10:34:34 +00:00
|
|
|
/**
|
|
|
|
* gpgme_cancel:
|
|
|
|
* @c: the context
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2000-12-29 10:34:34 +00:00
|
|
|
* Cancel the current operation. It is not guaranteed that it will work for
|
|
|
|
* all kinds of operations. It is especially useful in a passphrase callback
|
|
|
|
* to stop the system from asking another time for the passphrase.
|
|
|
|
**/
|
|
|
|
void
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_cancel (GpgmeCtx ctx)
|
2000-12-29 10:34:34 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
return_if_fail (ctx);
|
2001-01-30 18:03:21 +00:00
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
ctx->cancel = 1;
|
2000-12-29 10:34:34 +00:00
|
|
|
}
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
/**
|
|
|
|
* gpgme_get_notation:
|
2002-02-27 20:59:20 +00:00
|
|
|
* @c: the context
|
|
|
|
*
|
2001-09-17 08:25:36 +00:00
|
|
|
* If there is notation data available from the last signature check,
|
|
|
|
* this function may be used to return this notation data as a string.
|
|
|
|
* The string is an XML represantaton of that data embedded in a
|
|
|
|
* %<notation> container.
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2000-11-22 17:10:48 +00:00
|
|
|
* Return value: An XML string or NULL if no notation data is available.
|
|
|
|
**/
|
2000-11-15 21:36:48 +00:00
|
|
|
char *
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_get_notation (GpgmeCtx ctx)
|
2000-11-15 21:36:48 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
if (!ctx->notation)
|
|
|
|
return NULL;
|
|
|
|
return _gpgme_data_get_as_string (ctx->notation);
|
2000-11-15 21:36:48 +00:00
|
|
|
}
|
2000-11-07 13:32:38 +00:00
|
|
|
|
2001-08-28 11:11:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gpgme_get_op_info:
|
2002-02-27 20:59:20 +00:00
|
|
|
* @c: the context
|
|
|
|
* @reserved:
|
|
|
|
*
|
2001-08-28 11:11:10 +00:00
|
|
|
* Return information about the last information. The caller has to
|
|
|
|
* free the string. NULL is returned if there is not previous
|
|
|
|
* operation available or the operation has not yet finished.
|
|
|
|
*
|
|
|
|
* Here is a sample information we return:
|
2001-09-17 08:25:36 +00:00
|
|
|
* <literal>
|
|
|
|
* <![CDATA[
|
|
|
|
* <GnupgOperationInfo>
|
|
|
|
* <signature>
|
|
|
|
* <detached/> <!-- or cleartext or standard -->
|
|
|
|
* <algo>17</algo>
|
|
|
|
* <hashalgo>2</hashalgo>
|
|
|
|
* <micalg>pgp-sha1</micalg>
|
|
|
|
* <sigclass>01</sigclass>
|
|
|
|
* <created>9222222</created>
|
|
|
|
* <fpr>121212121212121212</fpr>
|
|
|
|
* </signature>
|
|
|
|
* </GnupgOperationInfo>
|
|
|
|
* ]]>
|
|
|
|
* </literal>
|
2002-02-27 20:59:20 +00:00
|
|
|
* Return value: NULL for no info available or an XML string
|
2001-08-28 11:11:10 +00:00
|
|
|
**/
|
|
|
|
char *
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_get_op_info (GpgmeCtx ctx, int reserved)
|
2001-08-28 11:11:10 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
if (!ctx || reserved)
|
|
|
|
return NULL; /* Invalid value. */
|
2002-02-27 20:59:20 +00:00
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
return _gpgme_data_get_as_string (ctx->op_info);
|
2001-08-28 11:11:10 +00:00
|
|
|
}
|
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
|
2001-08-28 11:11:10 +00:00
|
|
|
/*
|
|
|
|
* Store the data object with the operation info in the
|
2002-02-27 20:59:20 +00:00
|
|
|
* context. Caller should not use that object anymore.
|
2001-08-28 11:11:10 +00:00
|
|
|
*/
|
|
|
|
void
|
2002-01-15 19:58:41 +00:00
|
|
|
_gpgme_set_op_info (GpgmeCtx ctx, GpgmeData info)
|
2001-08-28 11:11:10 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
assert (ctx);
|
2001-08-28 11:11:10 +00:00
|
|
|
|
2002-02-27 20:59:20 +00:00
|
|
|
gpgme_data_release (ctx->op_info);
|
2002-01-15 19:58:41 +00:00
|
|
|
ctx->op_info = NULL;
|
2001-08-28 11:11:10 +00:00
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
if (info)
|
|
|
|
ctx->op_info = info;
|
2001-08-28 11:11:10 +00:00
|
|
|
}
|
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
|
2001-10-15 12:19:14 +00:00
|
|
|
GpgmeError
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_set_protocol (GpgmeCtx ctx, GpgmeProtocol protocol)
|
2001-10-15 12:19:14 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
if (!ctx)
|
2001-10-15 12:19:14 +00:00
|
|
|
return mk_error (Invalid_Value);
|
2002-02-27 20:59:20 +00:00
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
switch (protocol)
|
2001-10-15 12:19:14 +00:00
|
|
|
{
|
2001-10-17 19:13:11 +00:00
|
|
|
case GPGME_PROTOCOL_OpenPGP:
|
2002-01-15 19:58:41 +00:00
|
|
|
ctx->use_cms = 0;
|
2001-10-15 12:19:14 +00:00
|
|
|
break;
|
|
|
|
case GPGME_PROTOCOL_CMS:
|
2002-01-15 19:58:41 +00:00
|
|
|
ctx->use_cms = 1;
|
2001-10-15 12:19:14 +00:00
|
|
|
break;
|
|
|
|
case GPGME_PROTOCOL_AUTO:
|
|
|
|
return mk_error (Not_Implemented);
|
|
|
|
default:
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
}
|
2002-02-27 20:59:20 +00:00
|
|
|
|
2001-10-15 12:19:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-08-28 11:11:10 +00:00
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
/**
|
|
|
|
* gpgme_set_armor:
|
2002-02-27 20:59:20 +00:00
|
|
|
* @ctx: the context
|
2000-11-22 17:10:48 +00:00
|
|
|
* @yes: boolean value to set or clear that flag
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
|
|
|
* Enable or disable the use of an ascii armor for all output.
|
2000-11-22 17:10:48 +00:00
|
|
|
**/
|
2000-11-16 14:53:52 +00:00
|
|
|
void
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_set_armor (GpgmeCtx ctx, int yes)
|
2000-11-16 14:53:52 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
ctx->use_armor = yes;
|
2000-11-16 14:53:52 +00:00
|
|
|
}
|
2000-11-07 13:32:38 +00:00
|
|
|
|
2001-07-31 15:21:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gpgme_get_armor:
|
2002-01-15 19:58:41 +00:00
|
|
|
* @ctx: the context
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2001-07-31 15:21:58 +00:00
|
|
|
* Return the state of the armor flag which can be changed using
|
|
|
|
* gpgme_set_armor().
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2001-07-31 15:21:58 +00:00
|
|
|
* Return value: Boolean whether armor mode is to be used.
|
|
|
|
**/
|
2002-02-27 20:59:20 +00:00
|
|
|
int
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_get_armor (GpgmeCtx ctx)
|
2001-07-31 15:21:58 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
return ctx && ctx->use_armor;
|
2001-07-31 15:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
/**
|
|
|
|
* gpgme_set_textmode:
|
2002-01-15 19:58:41 +00:00
|
|
|
* @ctx: the context
|
2000-11-22 17:10:48 +00:00
|
|
|
* @yes: boolean flag whether textmode should be enabled
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2000-11-22 17:10:48 +00:00
|
|
|
* Enable or disable the use of the special textmode. Textmode is for example
|
2002-02-27 20:59:20 +00:00
|
|
|
* used for the RFC2015 signatures; note that the updated RFC 3156 mandates
|
2002-01-15 19:58:41 +00:00
|
|
|
* that the MUA does some preparations so that textmode is not needed anymore.
|
2000-11-22 17:10:48 +00:00
|
|
|
**/
|
2000-11-16 14:53:52 +00:00
|
|
|
void
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_set_textmode (GpgmeCtx ctx, int yes)
|
2000-11-16 14:53:52 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
ctx->use_textmode = yes;
|
2000-11-16 14:53:52 +00:00
|
|
|
}
|
2000-11-07 13:32:38 +00:00
|
|
|
|
2001-07-31 15:21:58 +00:00
|
|
|
/**
|
|
|
|
* gpgme_get_textmode:
|
2002-01-15 19:58:41 +00:00
|
|
|
* @ctx: the context
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2001-07-31 15:21:58 +00:00
|
|
|
* Return the state of the textmode flag which can be changed using
|
|
|
|
* gpgme_set_textmode().
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2001-07-31 15:21:58 +00:00
|
|
|
* Return value: Boolean whether textmode is to be used.
|
|
|
|
**/
|
2002-02-27 20:59:20 +00:00
|
|
|
int
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_get_textmode (GpgmeCtx ctx)
|
2001-07-31 15:21:58 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
return ctx && ctx->use_textmode;
|
2001-07-31 15:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-25 18:31:07 +00:00
|
|
|
/**
|
|
|
|
* gpgme_set_include_certs:
|
|
|
|
* @ctx: the context
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2002-02-25 18:31:07 +00:00
|
|
|
* Set the number of certifications to include in an S/MIME message.
|
|
|
|
* The default is 1 (only the cert of the sender). -1 means all certs,
|
|
|
|
* and -2 means all certs except the root cert.
|
|
|
|
*
|
|
|
|
* Return value: Boolean whether textmode is to be used.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gpgme_set_include_certs (GpgmeCtx ctx, int nr_of_certs)
|
|
|
|
{
|
|
|
|
if (nr_of_certs < -2)
|
|
|
|
ctx->include_certs = -2;
|
|
|
|
else
|
|
|
|
ctx->include_certs = nr_of_certs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gpgme_get_include_certs:
|
|
|
|
* @ctx: the context
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2002-02-25 18:31:07 +00:00
|
|
|
* Get the number of certifications to include in an S/MIME message.
|
|
|
|
*
|
|
|
|
* Return value: Boolean whether textmode is to be used.
|
|
|
|
**/
|
|
|
|
int
|
|
|
|
gpgme_get_include_certs (GpgmeCtx ctx)
|
|
|
|
{
|
|
|
|
return ctx->include_certs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-08 20:40:25 +00:00
|
|
|
/**
|
|
|
|
* gpgme_set_keylist_mode:
|
2002-01-15 19:58:41 +00:00
|
|
|
* @ctx: the context
|
2001-01-08 20:40:25 +00:00
|
|
|
* @mode: listing mode
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2002-02-06 00:08:47 +00:00
|
|
|
* This function changes the default behaviour of the keylisting
|
|
|
|
* functions. mode is a bitwise-OR of the GPGME_KEYLIST_* flags.
|
|
|
|
* The default mode is GPGME_KEYLIST_MODE_LOCAL.
|
|
|
|
*
|
|
|
|
* Return value: GPGME_Invalid_Value if ctx is not a context or mode
|
|
|
|
* not a valid mode.
|
2001-01-08 20:40:25 +00:00
|
|
|
**/
|
2002-02-06 00:08:47 +00:00
|
|
|
GpgmeError
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_set_keylist_mode (GpgmeCtx ctx, int mode)
|
2001-01-08 20:40:25 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
if (!ctx)
|
2002-02-06 00:08:47 +00:00
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
|
|
|
if (!((mode & GPGME_KEYLIST_MODE_LOCAL)
|
|
|
|
|| (mode & GPGME_KEYLIST_MODE_EXTERN)))
|
|
|
|
return mk_error (Invalid_Value);
|
|
|
|
|
2002-01-15 19:58:41 +00:00
|
|
|
ctx->keylist_mode = mode;
|
2002-02-06 00:08:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gpgme_get_keylist_mode:
|
|
|
|
* @ctx: the context
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2002-02-06 00:08:47 +00:00
|
|
|
* This function ch the default behaviour of the keylisting functions.
|
|
|
|
* Defines values for @mode are: %0 = normal, %1 = fast listing without
|
|
|
|
* information about key validity.
|
|
|
|
*
|
|
|
|
* Return value: 0 if ctx is not a valid context, or the current mode.
|
|
|
|
* Note that 0 is never a valid mode.
|
|
|
|
**/
|
|
|
|
int
|
|
|
|
gpgme_get_keylist_mode (GpgmeCtx ctx)
|
|
|
|
{
|
|
|
|
if (!ctx)
|
|
|
|
return 0;
|
|
|
|
return ctx->keylist_mode;
|
2001-01-08 20:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-12 13:31:25 +00:00
|
|
|
/**
|
|
|
|
* gpgme_set_passphrase_cb:
|
2002-02-27 20:59:20 +00:00
|
|
|
* @ctx: the context
|
2000-12-12 13:31:25 +00:00
|
|
|
* @cb: A callback function
|
|
|
|
* @cb_value: The value passed to the callback function
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2000-12-12 13:31:25 +00:00
|
|
|
* This function sets a callback function to be used to pass a passphrase
|
|
|
|
* to gpg. The preferred way to handle this is by using the gpg-agent, but
|
|
|
|
* because that beast is not ready for real use, you can use this passphrase
|
|
|
|
* thing.
|
|
|
|
*
|
|
|
|
* The callback function is defined as:
|
|
|
|
* <literal>
|
|
|
|
* typedef const char *(*GpgmePassphraseCb)(void*cb_value,
|
|
|
|
* const char *desc,
|
2002-01-22 15:32:44 +00:00
|
|
|
* void **r_hd);
|
2000-12-12 13:31:25 +00:00
|
|
|
* </literal>
|
|
|
|
* and called whenever gpgme needs a passphrase. DESC will have a nice
|
|
|
|
* text, to be used to prompt for the passphrase and R_HD is just a parameter
|
2002-01-15 19:58:41 +00:00
|
|
|
* to be used by the callback it self. Because the callback returns a const
|
2001-01-11 11:56:34 +00:00
|
|
|
* string, the callback might want to know when it can release resources
|
2000-12-12 13:31:25 +00:00
|
|
|
* assocated with that returned string; gpgme helps here by calling this
|
|
|
|
* passphrase callback with an DESC of %NULL as soon as it does not need
|
|
|
|
* the returned string anymore. The callback function might then choose
|
|
|
|
* to release resources depending on R_HD.
|
|
|
|
*
|
|
|
|
**/
|
2000-11-20 20:17:36 +00:00
|
|
|
void
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_set_passphrase_cb (GpgmeCtx ctx, GpgmePassphraseCb cb, void *cb_value)
|
2000-11-20 20:17:36 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
if (ctx)
|
2001-10-15 12:19:14 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
ctx->passphrase_cb = cb;
|
|
|
|
ctx->passphrase_cb_value = cb_value;
|
2001-10-15 12:19:14 +00:00
|
|
|
}
|
2000-11-20 20:17:36 +00:00
|
|
|
}
|
2000-12-06 12:17:10 +00:00
|
|
|
|
2002-04-22 21:58:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gpgme_get_passphrase_cb:
|
|
|
|
* @ctx: the context
|
2002-04-22 22:06:09 +00:00
|
|
|
* @r_cb: The current callback function
|
|
|
|
* @r_cb_value: The current value passed to the callback function
|
2002-04-22 21:58:26 +00:00
|
|
|
*
|
|
|
|
* This function returns the callback function to be used to pass a passphrase
|
|
|
|
* to the crypto engine.
|
|
|
|
**/
|
|
|
|
void
|
2002-04-22 22:06:09 +00:00
|
|
|
gpgme_get_passphrase_cb (GpgmeCtx ctx, GpgmePassphraseCb *r_cb, void **r_cb_value)
|
2002-04-22 21:58:26 +00:00
|
|
|
{
|
|
|
|
if (ctx)
|
|
|
|
{
|
2002-04-22 22:06:09 +00:00
|
|
|
if (r_cb)
|
|
|
|
*r_cb = ctx->passphrase_cb;
|
|
|
|
if (r_cb_value)
|
|
|
|
*r_cb_value = ctx->passphrase_cb_value;
|
2002-04-22 21:58:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-22 22:06:09 +00:00
|
|
|
if (r_cb)
|
|
|
|
*r_cb = NULL;
|
|
|
|
if (r_cb_value)
|
|
|
|
*r_cb_value = NULL;
|
2002-04-22 21:58:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-19 10:07:32 +00:00
|
|
|
/**
|
2001-10-15 12:19:14 +00:00
|
|
|
* gpgme_set_progress_cb:
|
2002-02-27 20:59:20 +00:00
|
|
|
* @ctx: the context
|
2000-12-19 10:07:32 +00:00
|
|
|
* @cb: A callback function
|
|
|
|
* @cb_value: The value passed to the callback function
|
2002-02-27 20:59:20 +00:00
|
|
|
*
|
2000-12-19 10:07:32 +00:00
|
|
|
* This function sets a callback function to be used as a progress indicator.
|
|
|
|
*
|
|
|
|
* The callback function is defined as:
|
|
|
|
* <literal>
|
2002-01-15 19:58:41 +00:00
|
|
|
* typedef void (*GpgmeProgressCb) (void *cb_value,
|
2000-12-19 10:07:32 +00:00
|
|
|
* const char *what, int type,
|
|
|
|
* int curretn, int total);
|
|
|
|
* </literal>
|
|
|
|
* For details on the progress events, see the entry for the PROGRESS
|
|
|
|
* status in the file doc/DETAILS of the GnuPG distribution.
|
|
|
|
**/
|
|
|
|
void
|
2002-01-15 19:58:41 +00:00
|
|
|
gpgme_set_progress_cb (GpgmeCtx ctx, GpgmeProgressCb cb, void *cb_value)
|
2000-12-19 10:07:32 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
if (ctx)
|
2001-10-15 12:19:14 +00:00
|
|
|
{
|
2002-01-15 19:58:41 +00:00
|
|
|
ctx->progress_cb = cb;
|
|
|
|
ctx->progress_cb_value = cb_value;
|
2001-10-15 12:19:14 +00:00
|
|
|
}
|
2000-12-19 10:07:32 +00:00
|
|
|
}
|
2002-04-22 21:58:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gpgme_get_progress_cb:
|
|
|
|
* @ctx: the context
|
2002-04-22 22:06:09 +00:00
|
|
|
* @r_cb: The current callback function
|
|
|
|
* @r_cb_value: The current value passed to the callback function
|
2002-04-22 21:58:26 +00:00
|
|
|
*
|
|
|
|
* This function returns the callback function to be used as a progress indicator.
|
|
|
|
**/
|
|
|
|
void
|
2002-04-22 22:06:09 +00:00
|
|
|
gpgme_get_progress_cb (GpgmeCtx ctx, GpgmeProgressCb *r_cb, void **r_cb_value)
|
2002-04-22 21:58:26 +00:00
|
|
|
{
|
|
|
|
if (ctx)
|
|
|
|
{
|
2002-04-22 22:06:09 +00:00
|
|
|
if (r_cb)
|
|
|
|
*r_cb = ctx->progress_cb;
|
|
|
|
if (r_cb_value)
|
|
|
|
*r_cb_value = ctx->progress_cb_value;
|
2002-04-22 21:58:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-22 22:06:09 +00:00
|
|
|
if (r_cb)
|
|
|
|
*r_cb = NULL;
|
|
|
|
if (r_cb_value)
|
|
|
|
*r_cb_value = NULL;
|
2002-04-22 21:58:26 +00:00
|
|
|
}
|
|
|
|
}
|