From: Werner Koch Date: Tue, 16 Feb 2010 20:07:03 +0000 (+0000) Subject: Add option GPGME_EXPORT_MODE_MINIMAL X-Git-Tag: gpgme-1.3.1~81 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2281024d4cb29c9c6742f7e9fbb031fe97f076c0;p=gpgme.git Add option GPGME_EXPORT_MODE_MINIMAL --- diff --git a/NEWS b/NEWS index 2933469..f85d50e 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,11 @@ Noteworthy changes in version 1.3.1 (unreleased) * Under development. + * Interface changes relative to the 1.3.0 release: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + GPGME_EXPORT_MODE_MINIMAL NEW. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Noteworthy changes in version 1.3.0 (2010-01-11) ------------------------------------------------ diff --git a/doc/gpgme.texi b/doc/gpgme.texi index cbbe493..d8891ea 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -3402,6 +3402,12 @@ practise to not send more than a few dozens key to a keyserver at one time. Using this flag requires that the @var{keydata} argument of the export function is set to @code{NULL}. +@item GPGME_EXPORT_MODE_MINIMAL +If this bit is set, the smallest possible key is exported. For OpenPGP +keys it removes all signatures except for the latest self-signatures. +For X.509 keys it has no effect. + + @end table diff --git a/src/ChangeLog b/src/ChangeLog index a90259c..e8e0363 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2010-02-16 Werner Koch + + * gpgme-tool.c (spacep, has_option, skip_options): New. + (cmd_export): Implement option --minimal. + + * gpgme.h.in (GPGME_EXPORT_MODE_MINIMAL): New. + * export.c (export_start, export_ext_start): Implement it. + * engine-gpg.c (export_common): Ditto. + 2010-01-25 Werner Koch * w32-io.c (_gpgme_io_connect): Fix return code check to make it work. diff --git a/src/engine-gpg.c b/src/engine-gpg.c index abfaaa3..a05fca2 100644 --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -1727,12 +1727,18 @@ static gpgme_error_t export_common (engine_gpg_t gpg, gpgme_export_mode_t mode, gpgme_data_t keydata, int use_armor) { - gpgme_error_t err; + gpgme_error_t err = 0; - if ((mode & ~GPGME_EXPORT_MODE_EXTERN)) + if ((mode & ~(GPGME_EXPORT_MODE_EXTERN + |GPGME_EXPORT_MODE_MINIMAL))) return gpg_error (GPG_ERR_NOT_SUPPORTED); - if ((mode & GPGME_EXPORT_MODE_EXTERN)) + if ((mode & GPGME_EXPORT_MODE_MINIMAL)) + err = add_arg (gpg, "--export-options=export-minimal"); + + if (err) + ; + else if ((mode & GPGME_EXPORT_MODE_EXTERN)) { err = add_arg (gpg, "--send-keys"); } diff --git a/src/export.c b/src/export.c index 16d9612..59463ef 100644 --- a/src/export.c +++ b/src/export.c @@ -1,6 +1,6 @@ /* export.c - Export a key. Copyright (C) 2000 Werner Koch (dd9jn) - Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH + Copyright (C) 2001, 2002, 2003, 2004, 2010 g10 Code GmbH This file is part of GPGME. @@ -15,9 +15,8 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser 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. */ + License along with this program; if not, see . + */ #if HAVE_CONFIG_H #include @@ -44,7 +43,8 @@ export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern, { gpgme_error_t err; - if ((mode & ~(GPGME_EXPORT_MODE_EXTERN))) + if ((mode & ~(GPGME_EXPORT_MODE_EXTERN + |GPGME_EXPORT_MODE_MINIMAL))) return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */ @@ -107,7 +107,8 @@ export_ext_start (gpgme_ctx_t ctx, int synchronous, const char *pattern[], { gpgme_error_t err; - if ((mode & ~(GPGME_EXPORT_MODE_EXTERN))) + if ((mode & ~(GPGME_EXPORT_MODE_EXTERN + |GPGME_EXPORT_MODE_MINIMAL))) return gpg_error (GPG_ERR_INV_VALUE); /* Invalid flags in MODE. */ if ((mode & GPGME_EXPORT_MODE_EXTERN)) diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c index fcfd468..57dcba3 100644 --- a/src/gpgme-tool.c +++ b/src/gpgme-tool.c @@ -468,6 +468,9 @@ argp_parse (const struct argp *argp, int argc, FILE *log_stream; char *program_name = "gpgme-tool"; +#define spacep(p) (*(p) == ' ' || *(p) == '\t') + + void log_error (int status, gpg_error_t errnum, const char *fmt, ...) GT_GCC_A_PRINTF(3,4); @@ -497,6 +500,35 @@ log_error (int status, gpg_error_t errnum, const char *fmt, ...) } +/* Check whether the option NAME appears in LINE. */ +static int +has_option (const char *line, const char *name) +{ + const char *s; + int n = strlen (name); + + s = strstr (line, name); + return (s && (s == line || spacep (s-1)) && (!s[n] || spacep (s+n))); +} + +/* Skip over options. It is assumed that leading spaces have been + removed (this is the case for lines passed to a handler from + assuan). Blanks after the options are also removed. */ +static char * +skip_options (char *line) +{ + while ( *line == '-' && line[1] == '-' ) + { + while (*line && !spacep (line)) + line++; + while (spacep (line)) + line++; + } + return line; +} + + + typedef gpg_error_t (*result_xml_write_cb_t) (void *hook, const void *buf, size_t len); @@ -2334,6 +2366,11 @@ cmd_import (assuan_context_t ctx, char *line) } +static const char hlp_export[] = + "EXPORT [--extern] [--minimal] []\n" + "\n" + "Export the keys described by PATTERN. Write the\n" + "the output to the object set by the last OUTPUT command."; static gpg_error_t cmd_export (assuan_context_t ctx, char *line) { @@ -2343,7 +2380,6 @@ cmd_export (assuan_context_t ctx, char *line) gpgme_data_t out_data; gpgme_export_mode_t mode = 0; const char *pattern[2]; - const char optstr[] = "--extern "; out_fd = assuan_get_output_fd (ctx); if (out_fd == ASSUAN_INVALID_FD) @@ -2352,11 +2388,13 @@ cmd_export (assuan_context_t ctx, char *line) if (err) return err; - if (strncasecmp (line, optstr, strlen (optstr))) - { - mode |= GPGME_EXPORT_MODE_EXTERN; - line += strlen (optstr); - } + if (has_option (line, "--extern")) + mode |= GPGME_EXPORT_MODE_EXTERN; + if (has_option (line, "--minimal")) + mode |= GPGME_EXPORT_MODE_MINIMAL; + + line = skip_options (line); + pattern[0] = line; pattern[1] = NULL; @@ -2695,7 +2733,7 @@ register_commands (assuan_context_t ctx) { "SIGN", cmd_sign }, { "VERIFY", cmd_verify }, { "IMPORT", cmd_import }, - { "EXPORT", cmd_export }, + { "EXPORT", cmd_export, hlp_export }, { "GENKEY", cmd_genkey }, { "DELETE", cmd_delete }, /* TODO: EDIT, CARD_EDIT (with INQUIRE) */ diff --git a/src/gpgme.h.in b/src/gpgme.h.in index 68ebd1a..57902f4 100644 --- a/src/gpgme.h.in +++ b/src/gpgme.h.in @@ -348,6 +348,7 @@ typedef unsigned int gpgme_keylist_mode_t; /* The available export mode flags. */ #define GPGME_EXPORT_MODE_EXTERN 2 +#define GPGME_EXPORT_MODE_MINIMAL 4 typedef unsigned int gpgme_export_mode_t;