2002-10-09 Marcus Brinkmann <marcus@g10code.de>

* rungpg.h (_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
	_gpgme_gpg_add_pm_data, _gpgme_gpg_housecleaning,
	_gpgme_gpg_set_simple_line_handler): Prototype removed.
	(_gpgme_gpg_set_verbosity): New prototype.
	* rungpg.c (_gpgme_gpg_add_data): Make static and rename to ...
	(add_data): ... this.
	(_gpgme_gpg_add_pm_data): Call add_data, not _gpgme_gpg_add_data.
	(_gpgme_gpg_set_command_handler): Likewise.
	(_gpgme_gpg_op_decrypt, _gpgme_gpg_op_edit, _gpgme_gpg_op_encrypt,
	_gpgme_gpg_op_encrypt_sign, _gpgme_gpg_op_export,
	_gpgme_gpg_op_genkey, _gpgme_gpg_op_import, _gpgme_gpg_op_sign,
	_gpgme_gpg_op_verify): Likewise.
	(_gpgme_gpg_add_pm_data): Rename to ...
	(add_pm_data): ... this.
	(_gpgme_gpg_op_verify): Call add_pm_data, not
	_gpgme_gpg_add_pm_data.
	(_gpgme_gpg_add_arg): Make static and rename to ...
	(add_arg): ... this.
	(_gpgme_gpg_set_command_handler, _gpgme_gpg_new,
	_gpgme_gpg_op_decrypt, _gpgme_gpg_op_delete,
	_gpgme_append_gpg_args_from_signers, _gpgme_gpg_op_edit,
	_gpgme_append_gpg_args_from_recipients, _gpgme_gpg_op_encrypt,
	_gpgme_gpg_op_encrypt_sign, _gpgme_gpg_op_export,
	_gpgme_gpg_op_genkey, _gpgme_gpg_op_import, _gpgme_gpg_op_keylist,
	_gpgme_gpg_op_keylist_ext, _gpgme_gpg_op_trustlist,
	_gpgme_gpg_op_sign, _gpgme_gpg_op_verify): Use add_arg, not
	_gpgme_gpg_add_arg.
	(_gpgme_gpg_set_verbosity): New function.
	(struct gpg_object_s): Remove member simple from colon.
	(_gpgme_gpg_set_colon_line_handler): Don't initialize simple.
	(_gpgme_gpg_set_simple_line_handler): Removed function.
	(read_colon_line): Don't check the GPG->colon.simple.
	* engine.c (_gpgme_engine_set_verbosity): Call
	_gpgme_gpg_set_verbosity instead _gpgme_gpg_add_arg.
This commit is contained in:
Marcus Brinkmann 2002-10-09 09:50:41 +00:00
parent 7385627265
commit 8646a29754
6 changed files with 353 additions and 332 deletions

View File

@ -1,3 +1,40 @@
2002-10-09 Marcus Brinkmann <marcus@g10code.de>
* rungpg.h (_gpgme_gpg_add_arg, _gpgme_gpg_add_data,
_gpgme_gpg_add_pm_data, _gpgme_gpg_housecleaning,
_gpgme_gpg_set_simple_line_handler): Prototype removed.
(_gpgme_gpg_set_verbosity): New prototype.
* rungpg.c (_gpgme_gpg_add_data): Make static and rename to ...
(add_data): ... this.
(_gpgme_gpg_add_pm_data): Call add_data, not _gpgme_gpg_add_data.
(_gpgme_gpg_set_command_handler): Likewise.
(_gpgme_gpg_op_decrypt, _gpgme_gpg_op_edit, _gpgme_gpg_op_encrypt,
_gpgme_gpg_op_encrypt_sign, _gpgme_gpg_op_export,
_gpgme_gpg_op_genkey, _gpgme_gpg_op_import, _gpgme_gpg_op_sign,
_gpgme_gpg_op_verify): Likewise.
(_gpgme_gpg_add_pm_data): Rename to ...
(add_pm_data): ... this.
(_gpgme_gpg_op_verify): Call add_pm_data, not
_gpgme_gpg_add_pm_data.
(_gpgme_gpg_add_arg): Make static and rename to ...
(add_arg): ... this.
(_gpgme_gpg_set_command_handler, _gpgme_gpg_new,
_gpgme_gpg_op_decrypt, _gpgme_gpg_op_delete,
_gpgme_append_gpg_args_from_signers, _gpgme_gpg_op_edit,
_gpgme_append_gpg_args_from_recipients, _gpgme_gpg_op_encrypt,
_gpgme_gpg_op_encrypt_sign, _gpgme_gpg_op_export,
_gpgme_gpg_op_genkey, _gpgme_gpg_op_import, _gpgme_gpg_op_keylist,
_gpgme_gpg_op_keylist_ext, _gpgme_gpg_op_trustlist,
_gpgme_gpg_op_sign, _gpgme_gpg_op_verify): Use add_arg, not
_gpgme_gpg_add_arg.
(_gpgme_gpg_set_verbosity): New function.
(struct gpg_object_s): Remove member simple from colon.
(_gpgme_gpg_set_colon_line_handler): Don't initialize simple.
(_gpgme_gpg_set_simple_line_handler): Removed function.
(read_colon_line): Don't check the GPG->colon.simple.
* engine.c (_gpgme_engine_set_verbosity): Call
_gpgme_gpg_set_verbosity instead _gpgme_gpg_add_arg.
2002-10-08 Marcus Brinkmann <marcus@g10code.de> 2002-10-08 Marcus Brinkmann <marcus@g10code.de>
* util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc, * util.h (_gpgme_malloc, _gpgme_realloc, _gpgme_calloc,

View File

@ -217,8 +217,7 @@ _gpgme_engine_set_verbosity (EngineObject engine, int verbosity)
switch (engine->protocol) switch (engine->protocol)
{ {
case GPGME_PROTOCOL_OpenPGP: case GPGME_PROTOCOL_OpenPGP:
while (verbosity-- > 0) _gpgme_gpg_set_verbosity (engine->engine.gpg, verbosity);
_gpgme_gpg_add_arg (engine->engine.gpg, "--verbose");
break; break;
case GPGME_PROTOCOL_CMS: case GPGME_PROTOCOL_CMS:
/* FIXME */ /* FIXME */

View File

@ -43,7 +43,7 @@ extern "C" {
AM_PATH_GPGME macro) check that this header matches the installed AM_PATH_GPGME macro) check that this header matches the installed
library. Warning: Do not edit the next line. configure will do library. Warning: Do not edit the next line. configure will do
that for you! */ that for you! */
#define GPGME_VERSION "0.3.12" #define GPGME_VERSION "0.4.0"
/* The opaque data types used by GPGME. */ /* The opaque data types used by GPGME. */

View File

@ -85,7 +85,7 @@ struct gpg_object_s
void *tag; void *tag;
} status; } status;
/* This is a kludge - see the comment at gpg_colon_line_handler */ /* This is a kludge - see the comment at gpg_colon_line_handler. */
struct struct
{ {
int fd[2]; int fd[2];
@ -96,7 +96,6 @@ struct gpg_object_s
GpgColonLineHandler fnc; /* this indicate use of this structrue */ GpgColonLineHandler fnc; /* this indicate use of this structrue */
void *fnc_value; void *fnc_value;
void *tag; void *tag;
int simple;
} colon; } colon;
char **argv; char **argv;
@ -220,6 +219,110 @@ close_notify_handler (int fd, void *opaque)
_gpgme_gpg_io_event (gpg, GPGME_EVENT_DONE, NULL); _gpgme_gpg_io_event (gpg, GPGME_EVENT_DONE, NULL);
} }
static GpgmeError
add_arg (GpgObject gpg, const char *arg)
{
struct arg_and_data_s *a;
assert (gpg);
assert (arg);
if (gpg->pm.active)
return 0;
a = malloc (sizeof *a + strlen (arg));
if (!a)
{
gpg->arg_error = 1;
return mk_error(Out_Of_Core);
}
a->next = NULL;
a->data = NULL;
a->dup_to = -1;
strcpy (a->arg, arg);
*gpg->argtail = a;
gpg->argtail = &a->next;
return 0;
}
static GpgmeError
add_data (GpgObject gpg, GpgmeData data, int dup_to, int inbound)
{
struct arg_and_data_s *a;
assert (gpg);
assert (data);
if (gpg->pm.active)
return 0;
a = malloc (sizeof *a - 1);
if (!a)
{
gpg->arg_error = 1;
return mk_error(Out_Of_Core);
}
a->next = NULL;
a->data = data;
a->inbound = inbound;
if (dup_to == -2)
{
a->print_fd = 1;
a->dup_to = -1;
}
else
{
a->print_fd = 0;
a->dup_to = dup_to;
}
*gpg->argtail = a;
gpg->argtail = &a->next;
return 0;
}
static GpgmeError
add_pm_data (GpgObject gpg, GpgmeData data, int what)
{
GpgmeError rc = 0;
assert (gpg->pm.used);
if (!what)
{
/* the signature */
assert (!gpg->pm.sig);
gpg->pm.sig = data;
}
else if (what == 1)
{
/* the signed data */
assert (!gpg->pm.text);
gpg->pm.text = data;
}
else
assert (0);
if (gpg->pm.sig && gpg->pm.text)
{
if (!gpg->pm.active)
{
/* Create the callback handler and connect it to stdin. */
GpgmeData tmp;
rc = gpgme_data_new_with_read_cb (&tmp, pipemode_cb, gpg);
if (!rc)
rc = add_data (gpg, tmp, 0, 0);
}
if (!rc)
{
/* Here we can reset the handler stuff. */
gpg->pm.stream_started = 0;
}
}
return rc;
}
const char * const char *
_gpgme_gpg_get_version (void) _gpgme_gpg_get_version (void)
{ {
@ -289,15 +392,15 @@ _gpgme_gpg_new (GpgObject *r_gpg)
goto leave; goto leave;
} }
gpg->status.eof = 0; gpg->status.eof = 0;
_gpgme_gpg_add_arg (gpg, "--status-fd"); add_arg (gpg, "--status-fd");
{ {
char buf[25]; char buf[25];
sprintf (buf, "%d", gpg->status.fd[1]); sprintf (buf, "%d", gpg->status.fd[1]);
_gpgme_gpg_add_arg (gpg, buf); add_arg (gpg, buf);
} }
_gpgme_gpg_add_arg (gpg, "--no-tty"); add_arg (gpg, "--no-tty");
_gpgme_gpg_add_arg (gpg, "--charset"); add_arg (gpg, "--charset");
_gpgme_gpg_add_arg (gpg, "utf8"); add_arg (gpg, "utf8");
leave: leave:
if (rc) if (rc)
@ -347,117 +450,27 @@ _gpgme_gpg_release (GpgObject gpg)
} }
void void
_gpgme_gpg_enable_pipemode ( GpgObject gpg ) _gpgme_gpg_enable_pipemode (GpgObject gpg)
{ {
gpg->pm.used = 1; gpg->pm.used = 1;
assert ( !gpg->pm.sig ); assert (!gpg->pm.sig);
assert ( !gpg->pm.text ); assert (!gpg->pm.text);
} }
GpgmeError GpgmeError
_gpgme_gpg_add_arg ( GpgObject gpg, const char *arg ) _gpgme_gpg_set_verbosity (GpgObject gpg, int verbosity)
{ {
struct arg_and_data_s *a; GpgmeError err = 0;
while (!err && verbosity-- > 0)
assert (gpg); err = add_arg (gpg, "--verbose");
assert (arg); return err;
if (gpg->pm.active)
return 0;
a = malloc ( sizeof *a + strlen (arg) );
if ( !a ) {
gpg->arg_error = 1;
return mk_error(Out_Of_Core);
}
a->next = NULL;
a->data = NULL;
a->dup_to = -1;
strcpy ( a->arg, arg );
*gpg->argtail = a;
gpg->argtail = &a->next;
return 0;
} }
GpgmeError /* Note, that the status_handler is allowed to modifiy the args
_gpgme_gpg_add_data (GpgObject gpg, GpgmeData data, int dup_to, int inbound) value. */
{
struct arg_and_data_s *a;
assert (gpg);
assert (data);
if (gpg->pm.active)
return 0;
a = malloc (sizeof *a - 1);
if (!a)
{
gpg->arg_error = 1;
return mk_error(Out_Of_Core);
}
a->next = NULL;
a->data = data;
a->inbound = inbound;
if (dup_to == -2)
{
a->print_fd = 1;
a->dup_to = -1;
}
else
{
a->print_fd = 0;
a->dup_to = dup_to;
}
*gpg->argtail = a;
gpg->argtail = &a->next;
return 0;
}
GpgmeError
_gpgme_gpg_add_pm_data ( GpgObject gpg, GpgmeData data, int what )
{
GpgmeError rc=0;
assert ( gpg->pm.used );
if ( !what ) {
/* the signature */
assert ( !gpg->pm.sig );
gpg->pm.sig = data;
}
else if (what == 1) {
/* the signed data */
assert ( !gpg->pm.text );
gpg->pm.text = data;
}
else {
assert (0);
}
if ( gpg->pm.sig && gpg->pm.text ) {
if ( !gpg->pm.active ) {
/* create the callback handler and connect it to stdin */
GpgmeData tmp;
rc = gpgme_data_new_with_read_cb ( &tmp, pipemode_cb, gpg );
if (!rc )
rc = _gpgme_gpg_add_data (gpg, tmp, 0, 0);
}
if ( !rc ) {
/* here we can reset the handler stuff */
gpg->pm.stream_started = 0;
}
}
return rc;
}
/*
* Note, that the status_handler is allowed to modifiy the args value
*/
void void
_gpgme_gpg_set_status_handler ( GpgObject gpg, _gpgme_gpg_set_status_handler (GpgObject gpg,
GpgStatusHandler fnc, void *fnc_value ) GpgStatusHandler fnc, void *fnc_value)
{ {
assert (gpg); assert (gpg);
if (gpg->pm.active) if (gpg->pm.active)
@ -467,10 +480,10 @@ _gpgme_gpg_set_status_handler ( GpgObject gpg,
gpg->status.fnc_value = fnc_value; gpg->status.fnc_value = fnc_value;
} }
/* Kludge to process --with-colon output */ /* Kludge to process --with-colon output. */
GpgmeError GpgmeError
_gpgme_gpg_set_colon_line_handler ( GpgObject gpg, _gpgme_gpg_set_colon_line_handler (GpgObject gpg,
GpgColonLineHandler fnc, void *fnc_value ) GpgColonLineHandler fnc, void *fnc_value)
{ {
assert (gpg); assert (gpg);
if (gpg->pm.active) if (gpg->pm.active)
@ -479,49 +492,31 @@ _gpgme_gpg_set_colon_line_handler ( GpgObject gpg,
gpg->colon.bufsize = 1024; gpg->colon.bufsize = 1024;
gpg->colon.readpos = 0; gpg->colon.readpos = 0;
gpg->colon.buffer = malloc (gpg->colon.bufsize); gpg->colon.buffer = malloc (gpg->colon.bufsize);
if (!gpg->colon.buffer) { if (!gpg->colon.buffer)
return mk_error (Out_Of_Core); return mk_error (Out_Of_Core);
}
if (_gpgme_io_pipe (gpg->colon.fd, 1) == -1) { if (_gpgme_io_pipe (gpg->colon.fd, 1) == -1)
free (gpg->colon.buffer); gpg->colon.buffer = NULL; {
free (gpg->colon.buffer);
gpg->colon.buffer = NULL;
return mk_error (Pipe_Error); return mk_error (Pipe_Error);
} }
if ( _gpgme_io_set_close_notify (gpg->colon.fd[0], if (_gpgme_io_set_close_notify (gpg->colon.fd[0], close_notify_handler, gpg)
close_notify_handler, gpg)
|| _gpgme_io_set_close_notify (gpg->colon.fd[1], || _gpgme_io_set_close_notify (gpg->colon.fd[1],
close_notify_handler, gpg) ) { close_notify_handler, gpg))
return mk_error (General_Error); return mk_error (General_Error);
}
gpg->colon.eof = 0; gpg->colon.eof = 0;
gpg->colon.fnc = fnc; gpg->colon.fnc = fnc;
gpg->colon.fnc_value = fnc_value; gpg->colon.fnc_value = fnc_value;
gpg->colon.simple = 0;
return 0; return 0;
} }
GpgmeError /* The Fnc will be called to get a value for one of the commands with
_gpgme_gpg_set_simple_line_handler ( GpgObject gpg, a key KEY. If the Code pssed to FNC is 0, the function may release
GpgColonLineHandler fnc, resources associated with the returned value from another call. To
void *fnc_value ) match such a second call to a first call, the returned value from
{ the first call is passed as keyword. */
GpgmeError err;
err = _gpgme_gpg_set_colon_line_handler (gpg, fnc, fnc_value);
if (!err)
gpg->colon.simple = 1;
return err;
}
/*
* The Fnc will be called to get a value for one of the commands with
* a key KEY. If the Code pssed to FNC is 0, the function may release
* resources associated with the returned value from another call. To
* match such a second call to a first call, the returned value from
* the first call is passed as keyword.
*/
GpgmeError GpgmeError
_gpgme_gpg_set_command_handler (GpgObject gpg, _gpgme_gpg_set_command_handler (GpgObject gpg,
GpgCommandHandler fnc, void *fnc_value, GpgCommandHandler fnc, void *fnc_value,
@ -538,8 +533,8 @@ _gpgme_gpg_set_command_handler (GpgObject gpg,
if (err) if (err)
return err; return err;
_gpgme_gpg_add_arg (gpg, "--command-fd"); add_arg (gpg, "--command-fd");
_gpgme_gpg_add_data (gpg, tmp, -2, 0); add_data (gpg, tmp, -2, 0);
gpg->cmd.cb_data = tmp; gpg->cmd.cb_data = tmp;
gpg->cmd.fnc = fnc; gpg->cmd.fnc = fnc;
gpg->cmd.fnc_value = fnc_value; gpg->cmd.fnc_value = fnc_value;
@ -550,29 +545,31 @@ _gpgme_gpg_set_command_handler (GpgObject gpg,
static void static void
free_argv ( char **argv ) free_argv (char **argv)
{ {
int i; int i;
for (i=0; argv[i]; i++ ) for (i = 0; argv[i]; i++)
free (argv[i]); free (argv[i]);
free (argv); free (argv);
} }
static void static void
free_fd_data_map ( struct fd_data_map_s *fd_data_map ) free_fd_data_map (struct fd_data_map_s *fd_data_map)
{ {
int i; int i;
if ( !fd_data_map ) if (!fd_data_map)
return; return;
for (i=0; fd_data_map[i].data; i++ ) { for (i = 0; fd_data_map[i].data; i++)
if ( fd_data_map[i].fd != -1 ) {
if (fd_data_map[i].fd != -1)
_gpgme_io_close (fd_data_map[i].fd); _gpgme_io_close (fd_data_map[i].fd);
if ( fd_data_map[i].peer_fd != -1 ) if (fd_data_map[i].peer_fd != -1)
_gpgme_io_close (fd_data_map[i].peer_fd); _gpgme_io_close (fd_data_map[i].peer_fd);
/* don't release data because this is only a reference */ /* Don't release data because this is only a reference. */
} }
free (fd_data_map); free (fd_data_map);
} }
@ -818,7 +815,7 @@ _gpgme_gpg_spawn (GpgObject gpg, void *opaque)
return mk_error (Invalid_Engine); return mk_error (Invalid_Engine);
/* Kludge, so that we don't need to check the return code of all the /* Kludge, so that we don't need to check the return code of all the
gpgme_gpg_add_arg(). we bail out here instead */ add_arg (). We bail out here instead. */
if (gpg->arg_error) if (gpg->arg_error)
return mk_error (Out_Of_Core); return mk_error (Out_Of_Core);
@ -1133,12 +1130,10 @@ read_status (GpgObject gpg)
} }
/* /* This colonline handler thing is not the clean way to do it. It
* This colonline handler thing is not the clean way to do it. might be better to enhance the GpgmeData object to act as a wrapper
* It might be better to enhance the GpgmeData object to act as for a callback. Same goes for the status thing. For now we use
* a wrapper for a callback. Same goes for the status thing. this thing here because it is easier to implement. */
* For now we use this thing here becuase it is easier to implement.
*/
static void static void
gpg_colon_line_handler (void *opaque, int fd) gpg_colon_line_handler (void *opaque, int fd)
{ {
@ -1199,10 +1194,10 @@ read_colon_line ( GpgObject gpg )
* some other printed information. * some other printed information.
*/ */
*p = 0; *p = 0;
if ( gpg->colon.simple if (*buffer && strchr (buffer, ':'))
|| (*buffer && strchr (buffer, ':')) ) { {
assert (gpg->colon.fnc); assert (gpg->colon.fnc);
gpg->colon.fnc ( gpg->colon.fnc_value, buffer ); gpg->colon.fnc (gpg->colon.fnc_value, buffer);
} }
/* To reuse the buffer for the next line we have to /* To reuse the buffer for the next line we have to
@ -1376,17 +1371,17 @@ _gpgme_gpg_op_decrypt (GpgObject gpg, GpgmeData ciph, GpgmeData plain)
{ {
GpgmeError err; GpgmeError err;
err = _gpgme_gpg_add_arg (gpg, "--decrypt"); err = add_arg (gpg, "--decrypt");
/* Tell the gpg object about the data. */ /* Tell the gpg object about the data. */
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--output"); err = add_arg (gpg, "--output");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "-"); err = add_arg (gpg, "-");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, plain, 1, 1); err = add_data (gpg, plain, 1, 1);
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, ciph, 0, 0); err = add_data (gpg, ciph, 0, 0);
return err; return err;
} }
@ -1396,18 +1391,17 @@ _gpgme_gpg_op_delete (GpgObject gpg, GpgmeKey key, int allow_secret)
{ {
GpgmeError err; GpgmeError err;
err = _gpgme_gpg_add_arg (gpg, allow_secret err = add_arg (gpg, allow_secret ? "--delete-secret-and-public-key"
? "--delete-secret-and-public-key"
: "--delete-key"); : "--delete-key");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err) if (!err)
{ {
const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, 0); const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, 0);
if (!s) if (!s)
err = mk_error (Invalid_Key); err = mk_error (Invalid_Key);
else else
err = _gpgme_gpg_add_arg (gpg, s); err = add_arg (gpg, s);
} }
return err; return err;
@ -1429,9 +1423,9 @@ _gpgme_append_gpg_args_from_signers (GpgObject gpg,
if (s) if (s)
{ {
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "-u"); err = add_arg (gpg, "-u");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, s); err = add_arg (gpg, s);
} }
gpgme_key_unref (key); gpgme_key_unref (key);
if (err) break; if (err) break;
@ -1446,22 +1440,22 @@ _gpgme_gpg_op_edit (GpgObject gpg, GpgmeKey key, GpgmeData out,
{ {
GpgmeError err; GpgmeError err;
err = _gpgme_gpg_add_arg (gpg, "--with-colons"); err = add_arg (gpg, "--with-colons");
if (!err) if (!err)
err = _gpgme_append_gpg_args_from_signers (gpg, ctx); err = _gpgme_append_gpg_args_from_signers (gpg, ctx);
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--edit-key"); err = add_arg (gpg, "--edit-key");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, out, 1, 1); err = add_data (gpg, out, 1, 1);
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err) if (!err)
{ {
const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, 0); const char *s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, 0);
if (!s) if (!s)
err = mk_error (Invalid_Key); err = mk_error (Invalid_Key);
else else
err = _gpgme_gpg_add_arg (gpg, s); err = add_arg (gpg, s);
} }
return err; return err;
@ -1478,9 +1472,9 @@ _gpgme_append_gpg_args_from_recipients (GpgObject gpg,
assert (rset); assert (rset);
for (r = rset->list; r; r = r->next) for (r = rset->list; r; r = r->next)
{ {
err = _gpgme_gpg_add_arg (gpg, "-r"); err = add_arg (gpg, "-r");
if (!err) if (!err)
_gpgme_gpg_add_arg (gpg, r->name); err = add_arg (gpg, r->name);
if (err) if (err)
break; break;
} }
@ -1495,17 +1489,17 @@ _gpgme_gpg_op_encrypt (GpgObject gpg, GpgmeRecipients recp,
GpgmeError err; GpgmeError err;
int symmetric = !recp; int symmetric = !recp;
err = _gpgme_gpg_add_arg (gpg, symmetric ? "--symmetric" : "--encrypt"); err = add_arg (gpg, symmetric ? "--symmetric" : "--encrypt");
if (!err && use_armor) if (!err && use_armor)
err = _gpgme_gpg_add_arg (gpg, "--armor"); err = add_arg (gpg, "--armor");
if (!symmetric) if (!symmetric)
{ {
/* If we know that all recipients are valid (full or ultimate trust) /* If we know that all recipients are valid (full or ultimate trust)
we can suppress further checks. */ we can suppress further checks. */
if (!err && !symmetric && _gpgme_recipients_all_valid (recp)) if (!err && !symmetric && _gpgme_recipients_all_valid (recp))
err = _gpgme_gpg_add_arg (gpg, "--always-trust"); err = add_arg (gpg, "--always-trust");
if (!err) if (!err)
err = _gpgme_append_gpg_args_from_recipients (gpg, recp); err = _gpgme_append_gpg_args_from_recipients (gpg, recp);
@ -1513,15 +1507,15 @@ _gpgme_gpg_op_encrypt (GpgObject gpg, GpgmeRecipients recp,
/* Tell the gpg object about the data. */ /* Tell the gpg object about the data. */
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--output"); err = add_arg (gpg, "--output");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "-"); err = add_arg (gpg, "-");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, ciph, 1, 1); err = add_data (gpg, ciph, 1, 1);
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, plain, 0, 0); err = add_data (gpg, plain, 0, 0);
return err; return err;
} }
@ -1533,16 +1527,16 @@ _gpgme_gpg_op_encrypt_sign (GpgObject gpg, GpgmeRecipients recp,
{ {
GpgmeError err; GpgmeError err;
err = _gpgme_gpg_add_arg (gpg, "--encrypt"); err = add_arg (gpg, "--encrypt");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--sign"); err = add_arg (gpg, "--sign");
if (!err && use_armor) if (!err && use_armor)
err = _gpgme_gpg_add_arg (gpg, "--armor"); err = add_arg (gpg, "--armor");
/* If we know that all recipients are valid (full or ultimate trust) /* If we know that all recipients are valid (full or ultimate trust)
* we can suppress further checks */ * we can suppress further checks */
if (!err && _gpgme_recipients_all_valid (recp)) if (!err && _gpgme_recipients_all_valid (recp))
err = _gpgme_gpg_add_arg (gpg, "--always-trust"); err = add_arg (gpg, "--always-trust");
if (!err) if (!err)
err = _gpgme_append_gpg_args_from_recipients (gpg, recp); err = _gpgme_append_gpg_args_from_recipients (gpg, recp);
@ -1552,15 +1546,15 @@ _gpgme_gpg_op_encrypt_sign (GpgObject gpg, GpgmeRecipients recp,
/* Tell the gpg object about the data. */ /* Tell the gpg object about the data. */
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--output"); err = add_arg (gpg, "--output");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "-"); err = add_arg (gpg, "-");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, ciph, 1, 1); err = add_data (gpg, ciph, 1, 1);
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, plain, 0, 0); err = add_data (gpg, plain, 0, 0);
return err; return err;
} }
@ -1571,13 +1565,13 @@ _gpgme_gpg_op_export (GpgObject gpg, GpgmeRecipients recp,
{ {
GpgmeError err; GpgmeError err;
err = _gpgme_gpg_add_arg (gpg, "--export"); err = add_arg (gpg, "--export");
if (!err && use_armor) if (!err && use_armor)
err = _gpgme_gpg_add_arg (gpg, "--armor"); err = add_arg (gpg, "--armor");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, keydata, 1, 1); err = add_data (gpg, keydata, 1, 1);
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err) if (!err)
{ {
@ -1586,7 +1580,7 @@ _gpgme_gpg_op_export (GpgObject gpg, GpgmeRecipients recp,
err = gpgme_recipients_enum_open (recp, &ec); err = gpgme_recipients_enum_open (recp, &ec);
while (!err && (s = gpgme_recipients_enum_read (recp, &ec))) while (!err && (s = gpgme_recipients_enum_read (recp, &ec)))
err = _gpgme_gpg_add_arg (gpg, s); err = add_arg (gpg, s);
if (!err) if (!err)
err = gpgme_recipients_enum_close (recp, &ec); err = gpgme_recipients_enum_close (recp, &ec);
} }
@ -1610,11 +1604,11 @@ _gpgme_gpg_op_genkey (GpgObject gpg, GpgmeData help_data, int use_armor,
if (pubkey || seckey) if (pubkey || seckey)
return err = mk_error (Not_Implemented); return err = mk_error (Not_Implemented);
err = _gpgme_gpg_add_arg (gpg, "--gen-key"); err = add_arg (gpg, "--gen-key");
if (!err && use_armor) if (!err && use_armor)
err = _gpgme_gpg_add_arg (gpg, "--armor"); err = add_arg (gpg, "--armor");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, help_data, 0, 0); err = add_data (gpg, help_data, 0, 0);
return err; return err;
} }
@ -1624,9 +1618,9 @@ _gpgme_gpg_op_import (GpgObject gpg, GpgmeData keydata)
{ {
GpgmeError err; GpgmeError err;
err = _gpgme_gpg_add_arg (gpg, "--import"); err = add_arg (gpg, "--import");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, keydata, 0, 0); err = add_data (gpg, keydata, 0, 0);
return err; return err;
} }
@ -1638,23 +1632,22 @@ _gpgme_gpg_op_keylist (GpgObject gpg, const char *pattern, int secret_only,
{ {
GpgmeError err; GpgmeError err;
err = _gpgme_gpg_add_arg (gpg, "--with-colons"); err = add_arg (gpg, "--with-colons");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--fixed-list-mode"); err = add_arg (gpg, "--fixed-list-mode");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--with-fingerprint"); err = add_arg (gpg, "--with-fingerprint");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, err = add_arg (gpg, (keylist_mode & GPGME_KEYLIST_MODE_SIGS) ?
(keylist_mode & GPGME_KEYLIST_MODE_SIGS)?
"--check-sigs" : "--check-sigs" :
secret_only ? "--list-secret-keys" secret_only ? "--list-secret-keys"
: "--list-keys"); : "--list-keys");
/* Tell the gpg object about the data */ /* Tell the gpg object about the data. */
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err && pattern && *pattern) if (!err && pattern && *pattern)
err = _gpgme_gpg_add_arg (gpg, pattern); err = add_arg (gpg, pattern);
return err; return err;
} }
@ -1669,22 +1662,21 @@ _gpgme_gpg_op_keylist_ext (GpgObject gpg, const char *pattern[],
if (reserved) if (reserved)
return mk_error (Invalid_Value); return mk_error (Invalid_Value);
err = _gpgme_gpg_add_arg (gpg, "--with-colons"); err = add_arg (gpg, "--with-colons");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--fixed-list-mode"); err = add_arg (gpg, "--fixed-list-mode");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--with-fingerprint"); err = add_arg (gpg, "--with-fingerprint");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, secret_only ? "--list-secret-keys" err = add_arg (gpg, secret_only ? "--list-secret-keys" : "--list-keys");
: "--list-keys");
/* Tell the gpg object about the data */ /* Tell the gpg object about the data. */
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err && pattern && *pattern) if (!err && pattern && *pattern)
{ {
while (*pattern && **pattern) while (*pattern && **pattern)
err = _gpgme_gpg_add_arg (gpg, *(pattern++)); err = add_arg (gpg, *(pattern++));
} }
return err; return err;
@ -1699,16 +1691,16 @@ _gpgme_gpg_op_sign (GpgObject gpg, GpgmeData in, GpgmeData out,
GpgmeError err; GpgmeError err;
if (mode == GPGME_SIG_MODE_CLEAR) if (mode == GPGME_SIG_MODE_CLEAR)
err = _gpgme_gpg_add_arg (gpg, "--clearsign"); err = add_arg (gpg, "--clearsign");
else else
{ {
err = _gpgme_gpg_add_arg (gpg, "--sign"); err = add_arg (gpg, "--sign");
if (!err && mode == GPGME_SIG_MODE_DETACH) if (!err && mode == GPGME_SIG_MODE_DETACH)
err = _gpgme_gpg_add_arg (gpg, "--detach"); err = add_arg (gpg, "--detach");
if (!err && use_armor) if (!err && use_armor)
err = _gpgme_gpg_add_arg (gpg, "--armor"); err = add_arg (gpg, "--armor");
if (!err && use_textmode) if (!err && use_textmode)
_gpgme_gpg_add_arg (gpg, "--textmode"); add_arg (gpg, "--textmode");
} }
if (!err) if (!err)
@ -1716,9 +1708,9 @@ _gpgme_gpg_op_sign (GpgObject gpg, GpgmeData in, GpgmeData out,
/* Tell the gpg object about the data. */ /* Tell the gpg object about the data. */
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, in, 0, 0); err = add_data (gpg, in, 0, 0);
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, out, 1, 1); err = add_data (gpg, out, 1, 1);
return err; return err;
} }
@ -1728,21 +1720,22 @@ _gpgme_gpg_op_trustlist (GpgObject gpg, const char *pattern)
{ {
GpgmeError err; GpgmeError err;
err = _gpgme_gpg_add_arg (gpg, "--with-colons"); err = add_arg (gpg, "--with-colons");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--list-trust-path"); err = add_arg (gpg, "--list-trust-path");
/* Tell the gpg object about the data */ /* Tell the gpg object about the data. */
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, pattern); err = add_arg (gpg, pattern);
return err; return err;
} }
GpgmeError GpgmeError
_gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData signed_text, GpgmeData plaintext) _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData signed_text,
GpgmeData plaintext)
{ {
GpgmeError err = 0; GpgmeError err = 0;
@ -1750,41 +1743,41 @@ _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData signed_text, Gpgme
{ {
/* Normal or cleartext signature. */ /* Normal or cleartext signature. */
err = _gpgme_gpg_add_arg (gpg, "--output"); err = add_arg (gpg, "--output");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "-"); err = add_arg (gpg, "-");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, sig, 0, 0); err = add_data (gpg, sig, 0, 0);
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, plaintext, 1, 1); err = add_data (gpg, plaintext, 1, 1);
} }
else else
{ {
if (gpg->pm.used) if (gpg->pm.used)
{ {
err = _gpgme_gpg_add_arg (gpg, gpg->pm.used ? "--pipemode" : "--verify"); err = add_arg (gpg, gpg->pm.used ? "--pipemode" : "--verify");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err) if (!err)
err = _gpgme_gpg_add_pm_data (gpg, sig, 0); err = add_pm_data (gpg, sig, 0);
if (!err) if (!err)
err = _gpgme_gpg_add_pm_data (gpg, signed_text, 1); err = add_pm_data (gpg, signed_text, 1);
} }
else else
{ {
err = _gpgme_gpg_add_arg (gpg, "--verify"); err = add_arg (gpg, "--verify");
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "--"); err = add_arg (gpg, "--");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, sig, -1, 0); err = add_data (gpg, sig, -1, 0);
if (signed_text) if (signed_text)
{ {
if (!err) if (!err)
err = _gpgme_gpg_add_arg (gpg, "-"); err = add_arg (gpg, "-");
if (!err) if (!err)
err = _gpgme_gpg_add_data (gpg, signed_text, 0, 0); err = add_data (gpg, signed_text, 0, 0);
} }
} }
} }

View File

@ -1,53 +1,45 @@
/* rungpg.h - gpg calling functions /* rungpg.h - GPGME GnuPG engine calling functions.
* Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH Copyright (C) 2001, 2002 g10 Code GmbH
*
* This file is part of GPGME. This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify GPGME is free software; you can redistribute it and/or modify it
* it under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, GPGME is distributed in the hope that it will be useful, but
* but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* GNU General Public License for more details. General Public License for more details.
*
* You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software along with GPGME; if not, write to the Free Software Foundation,
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
*/
#ifndef RUNGPG_H #ifndef RUNGPG_H
#define RUNGPG_H #define RUNGPG_H
#include "types.h" #include "types.h"
typedef void (*GpgStatusHandler)( GpgmeCtx, GpgmeStatusCode code, char *args ); typedef void (*GpgStatusHandler) (GpgmeCtx, GpgmeStatusCode code, char *args);
typedef void (*GpgColonLineHandler)( GpgmeCtx, char *line ); typedef void (*GpgColonLineHandler)( GpgmeCtx, char *line);
typedef const char *(*GpgCommandHandler)(void*, GpgmeStatusCode code, typedef const char *(*GpgCommandHandler) (void*, GpgmeStatusCode code,
const char *keyword); const char *keyword);
const char *_gpgme_gpg_get_version (void); const char *_gpgme_gpg_get_version (void);
GpgmeError _gpgme_gpg_check_version (void); GpgmeError _gpgme_gpg_check_version (void);
GpgmeError _gpgme_gpg_new ( GpgObject *r_gpg ); GpgmeError _gpgme_gpg_new (GpgObject *r_gpg);
void _gpgme_gpg_release ( GpgObject gpg ); void _gpgme_gpg_release (GpgObject gpg);
void _gpgme_gpg_housecleaning (void); void _gpgme_gpg_enable_pipemode (GpgObject gpg);
void _gpgme_gpg_enable_pipemode ( GpgObject gpg ); GpgmeError _gpgme_gpg_set_verbosity (GpgObject gpg, int verbosity);
GpgmeError _gpgme_gpg_add_arg ( GpgObject gpg, const char *arg ); void _gpgme_gpg_set_status_handler (GpgObject gpg, GpgStatusHandler fnc,
GpgmeError _gpgme_gpg_add_data (GpgObject gpg, GpgmeData data, int dup_to, int inbound);
GpgmeError _gpgme_gpg_add_pm_data ( GpgObject gpg, GpgmeData data, int what );
void _gpgme_gpg_set_status_handler (GpgObject gpg,
GpgStatusHandler fnc,
void *fnc_value); void *fnc_value);
GpgmeError _gpgme_gpg_set_colon_line_handler ( GpgObject gpg, GpgmeError _gpgme_gpg_set_colon_line_handler (GpgObject gpg,
GpgColonLineHandler fnc, GpgColonLineHandler fnc,
void *fnc_value ); void *fnc_value);
GpgmeError _gpgme_gpg_set_simple_line_handler ( GpgObject gpg,
GpgColonLineHandler fnc,
void *fnc_value );
GpgmeError _gpgme_gpg_set_command_handler (GpgObject gpg, GpgmeError _gpgme_gpg_set_command_handler (GpgObject gpg,
GpgCommandHandler fnc, GpgCommandHandler fnc,
void *fnc_value, void *fnc_value,