aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2003-04-15 15:46:13 +0000
committerWerner Koch <[email protected]>2003-04-15 15:46:13 +0000
commitb394776a80e2e192eeaf5de82b2df8660298a091 (patch)
tree93e71726d93f4ca7c1289ddb70f19c067b51519d
parent* gpg.sgml: Document --enable-progress-filter. (diff)
downloadgnupg-b394776a80e2e192eeaf5de82b2df8660298a091.tar.gz
gnupg-b394776a80e2e192eeaf5de82b2df8660298a091.zip
* Makefile.am (AM_CFLAGS): Make use of AM_CFLAGS and AM_LDFLAGS.
* g10.c, options.h: New option --enable-progress-filter. * progress.c (handle_progress): Make use of it.
-rw-r--r--g10/ChangeLog28
-rw-r--r--g10/Makefile.am9
-rw-r--r--g10/decrypt.c7
-rw-r--r--g10/encode.c6
-rw-r--r--g10/filter.h14
-rw-r--r--g10/g10.c6
-rw-r--r--g10/main.h2
-rw-r--r--g10/openfile.c7
-rw-r--r--g10/options.h4
-rw-r--r--g10/plaintext.c15
-rw-r--r--g10/progress.c104
-rw-r--r--g10/sign.c20
-rw-r--r--g10/verify.c4
13 files changed, 209 insertions, 17 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index eb358b1a5..548b499a1 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,31 @@
+2003-04-15 Werner Koch <[email protected]>
+
+ * Makefile.am (AM_CFLAGS): Make use of AM_CFLAGS and AM_LDFLAGS.
+
+ * g10.c, options.h: New option --enable-progress-filter.
+ * progress.c (handle_progress): Make use of it.
+
+2003-04-15 Marcus Brinkmann <[email protected]>
+
+ * progress.c: New file.
+ * Makefile.am (common_source): Add progress.c.
+ * filter.h (progress_filter_context_t): New type.
+ (progress_filter, handle_progress): New prototypes.
+ * main.h (open_sigfile): New argument for prototype.
+ * openfile.c (open_sigfile): New argument to install progress
+ filter.
+ * encode.c (encode_simple): New variable PFX. Register
+ progress filter. Install text_filter after that.
+ (encode_crypt): Likewise.
+ * sign.c (sign_file): Likewise.
+ (clearsign_file): Likewise.
+ * decrypt.c (decrypt_message): Likewise.
+ (decrypt_messages): Likewise.
+ * verify.c (verify_signatures): Likewise.
+ (verify_one_file): Likewise.
+ * plaintext.c (hash_datafiles): Likewise.
+ (ask_for_detached_datafile): Likewise.
+
2003-04-10 Werner Koch <[email protected]>
* passphrase.c (read_passphrase_from_fd): Do a dummy read if the
diff --git a/g10/Makefile.am b/g10/Makefile.am
index a70a83734..c12ff46e2 100644
--- a/g10/Makefile.am
+++ b/g10/Makefile.am
@@ -1,4 +1,5 @@
-# Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+# Copyright (C) 1998, 1999, 2000, 2001, 2002,
+# 2003 Free Software Foundation, Inc.
#
# This file is part of GnuPG.
#
@@ -22,9 +23,10 @@ INCLUDES = -I.. -I$(top_srcdir)/include -I$(top_srcdir)/intl
EXTRA_DIST = options.skel
# it seems that we can't use this with automake 1.5
#OMIT_DEPENDENCIES = zlib.h zconf.h
-LDFLAGS = @LDFLAGS@
libexecdir = @libexecdir@/@PACKAGE@
-CFLAGS = @CFLAGS@ -DGNUPG_LIBEXECDIR="\"$(libexecdir)\""
+if ! HAVE_DOSISH_SYSTEM
+AM_CFLAGS = -DGNUPG_LIBEXECDIR="\"$(libexecdir)\""
+endif
needed_libs = ../cipher/libcipher.a ../mpi/libmpi.a ../util/libutil.a @CAPLIBS@
#noinst_PROGRAMS = gpgd
@@ -46,6 +48,7 @@ common_source = \
armor.c \
mdfilter.c \
textfilter.c \
+ progress.c \
misc.c \
options.h \
openfile.c \
diff --git a/g10/decrypt.c b/g10/decrypt.c
index bea16b728..df778d1ad 100644
--- a/g10/decrypt.c
+++ b/g10/decrypt.c
@@ -51,6 +51,7 @@ decrypt_message( const char *filename )
{
IOBUF fp;
armor_filter_context_t afx;
+ progress_filter_context_t pfx;
int rc;
int no_out=0;
@@ -61,6 +62,8 @@ decrypt_message( const char *filename )
return G10ERR_OPEN_FILE;
}
+ handle_progress (&pfx, fp, filename);
+
if( !opt.no_armor ) {
if( use_armor_filter( fp ) ) {
memset( &afx, 0, sizeof afx);
@@ -84,6 +87,7 @@ decrypt_messages(int nfiles, char **files)
{
IOBUF fp;
armor_filter_context_t afx;
+ progress_filter_context_t pfx;
char *p, *output = NULL;
int rc = 0;
@@ -106,6 +110,9 @@ decrypt_messages(int nfiles, char **files)
log_error(_("can't open `%s'\n"), print_fname_stdin(*files));
goto next_file;
}
+
+ handle_progress (&pfx, fp, *files);
+
if (!opt.no_armor)
{
if (use_armor_filter(fp))
diff --git a/g10/encode.c b/g10/encode.c
index d1b0cdb11..a7396c98c 100644
--- a/g10/encode.c
+++ b/g10/encode.c
@@ -164,6 +164,7 @@ encode_simple( const char *filename, int mode, int compat )
armor_filter_context_t afx;
compress_filter_context_t zfx;
text_filter_context_t tfx;
+ progress_filter_context_t pfx;
int do_compress = opt.compress && !opt.rfc1991;
memset( &cfx, 0, sizeof cfx);
@@ -179,6 +180,8 @@ encode_simple( const char *filename, int mode, int compat )
return G10ERR_OPEN_FILE;
}
+ handle_progress (&pfx, inp, filename);
+
if( opt.textmode )
iobuf_push_filter( inp, text_filter, &tfx );
@@ -386,6 +389,7 @@ encode_crypt( const char *filename, STRLIST remusr )
armor_filter_context_t afx;
compress_filter_context_t zfx;
text_filter_context_t tfx;
+ progress_filter_context_t pfx;
PK_LIST pk_list,work_list;
int do_compress = opt.compress && !opt.rfc1991;
@@ -422,6 +426,8 @@ encode_crypt( const char *filename, STRLIST remusr )
else if( opt.verbose )
log_info(_("reading from `%s'\n"), filename? filename: "[stdin]");
+ handle_progress (&pfx, inp, filename);
+
if( opt.textmode )
iobuf_push_filter( inp, text_filter, &tfx );
diff --git a/g10/filter.h b/g10/filter.h
index c933d2383..ec1c5f744 100644
--- a/g10/filter.h
+++ b/g10/filter.h
@@ -109,6 +109,14 @@ typedef struct {
} text_filter_context_t;
+typedef struct {
+ char *what; /* description */
+ u32 last_time; /* last time reported */
+ unsigned long last; /* last amount reported */
+ unsigned long offset; /* current amount */
+ unsigned long total; /* total amount */
+} progress_filter_context_t;
+
/* encrypt_filter_context_t defined in main.h */
/*-- mdfilter.c --*/
@@ -137,6 +145,10 @@ int text_filter( void *opaque, int control,
int copy_clearsig_text( IOBUF out, IOBUF inp, MD_HANDLE md,
int escape_dash, int escape_from, int pgp2mode );
-
+/*-- progress.c --*/
+int progress_filter (void *opaque, int control,
+ IOBUF a, byte *buf, size_t *ret_len);
+void handle_progress (progress_filter_context_t *pfx,
+ IOBUF inp, char *name);
#endif /*G10_FILTER_H*/
diff --git a/g10/g10.c b/g10/g10.c
index 956a7ddd3..9b609c072 100644
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -1,5 +1,5 @@
/* g10.c - The GnuPG utility (main for gpg)
- * Copyright (C) 1998,1999,2000,2001,2002 Free Software Foundation, Inc.
+ * Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -313,6 +313,7 @@ enum cmd_and_opt_values { aNull = 0,
oNoStrict,
oMangleDosFilenames,
oNoMangleDosFilenames,
+ oEnableProgressFilter,
aTest };
@@ -616,6 +617,7 @@ static ARGPARSE_OPTS opts[] = {
{ oNoStrict, "no-strict", 0, "@" },
{ oMangleDosFilenames, "mangle-dos-filenames", 0, "@" },
{ oNoMangleDosFilenames, "no-mangle-dos-filenames", 0, "@" },
+ { oEnableProgressFilter, "enable-progress-filter", 0, "@" },
{0} };
@@ -1818,6 +1820,8 @@ main( int argc, char **argv )
case oMangleDosFilenames: opt.mangle_dos_filenames = 1; break;
case oNoMangleDosFilenames: opt.mangle_dos_filenames = 0; break;
+ case oEnableProgressFilter: opt.enable_progress_filter = 1; break;
+
default : pargs.err = configfp? 1:2; break;
}
}
diff --git a/g10/main.h b/g10/main.h
index 9706ffc49..84a2705d8 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -146,7 +146,7 @@ int overwrite_filep( const char *fname );
char *make_outfile_name( const char *iname );
char *ask_outfile_name( const char *name, size_t namelen );
int open_outfile( const char *iname, int mode, IOBUF *a );
-IOBUF open_sigfile( const char *iname );
+IOBUF open_sigfile( const char *iname, progress_filter_context_t *pfx );
void try_make_homedir( const char *fname );
/*-- seskey.c --*/
diff --git a/g10/openfile.c b/g10/openfile.c
index 34be71d62..81e5d2d43 100644
--- a/g10/openfile.c
+++ b/g10/openfile.c
@@ -264,7 +264,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
* Return NULL if such a file is not available.
*/
IOBUF
-open_sigfile( const char *iname )
+open_sigfile( const char *iname, progress_filter_context_t *pfx )
{
IOBUF a = NULL;
size_t len;
@@ -280,7 +280,10 @@ open_sigfile( const char *iname )
a = iobuf_open( buf );
if( a && opt.verbose )
log_info(_("assuming signed data in `%s'\n"), buf );
- m_free(buf);
+ if (a && pfx)
+ handle_progress (pfx, a, buf);
+ else
+ m_free(buf);
}
}
return a;
diff --git a/g10/options.h b/g10/options.h
index 12a1e2f73..a2868e493 100644
--- a/g10/options.h
+++ b/g10/options.h
@@ -1,5 +1,6 @@
/* options.h
- * Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002,
+ * 2003 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -181,6 +182,7 @@ struct {
struct groupitem *grouplist;
int strict;
int mangle_dos_filenames;
+ int enable_progress_filter;
} opt;
diff --git a/g10/plaintext.c b/g10/plaintext.c
index a248598cd..89322670e 100644
--- a/g10/plaintext.c
+++ b/g10/plaintext.c
@@ -357,11 +357,16 @@ int
ask_for_detached_datafile( MD_HANDLE md, MD_HANDLE md2,
const char *inname, int textmode )
{
+ progress_filter_context_t pfx;
+ int dealloc_pfx_name = 1;
char *answer = NULL;
IOBUF fp;
int rc = 0;
- fp = open_sigfile( inname ); /* open default file */
+ fp = open_sigfile( inname, &pfx ); /* open default file */
+ if (!fp)
+ dealloc_pfx_name = 0;
+
if( !fp && !opt.batch ) {
int any=0;
tty_printf(_("Detached signature.\n"));
@@ -395,7 +400,8 @@ ask_for_detached_datafile( MD_HANDLE md, MD_HANDLE md2,
}
do_hash( md, md2, fp, textmode );
iobuf_close(fp);
-
+ if (dealloc_pfx_name)
+ m_free (pfx.what);
leave:
m_free(answer);
@@ -412,15 +418,17 @@ int
hash_datafiles( MD_HANDLE md, MD_HANDLE md2, STRLIST files,
const char *sigfilename, int textmode )
{
+ progress_filter_context_t pfx;
IOBUF fp;
STRLIST sl;
if( !files ) {
/* check whether we can open the signed material */
- fp = open_sigfile( sigfilename );
+ fp = open_sigfile( sigfilename, &pfx );
if( fp ) {
do_hash( md, md2, fp, textmode );
iobuf_close(fp);
+ m_free (pfx.what);
return 0;
}
log_error (_("no signed data\n"));
@@ -435,6 +443,7 @@ hash_datafiles( MD_HANDLE md, MD_HANDLE md2, STRLIST files,
print_fname_stdin(sl->d));
return G10ERR_OPEN_FILE;
}
+ handle_progress (&pfx, fp, sl->d);
do_hash( md, md2, fp, textmode );
iobuf_close(fp);
}
diff --git a/g10/progress.c b/g10/progress.c
new file mode 100644
index 000000000..7313e29e5
--- /dev/null
+++ b/g10/progress.c
@@ -0,0 +1,104 @@
+/* progress.c
+ * Copyright (C) 2003 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG 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.
+ *
+ * GnuPG 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 "iobuf.h"
+#include "filter.h"
+#include "status.h"
+#include "options.h"
+
+/****************
+ * The filter is used to report progress to the user.
+ */
+int
+progress_filter (void *opaque, int control,
+ IOBUF a, byte *buf, size_t *ret_len)
+{
+ int rc = 0;
+ progress_filter_context_t *pfx = opaque;
+
+ if (control == IOBUFCTRL_INIT)
+ {
+ char buffer[50];
+
+ pfx->last = 0;
+ pfx->offset = 0;
+ pfx->last_time = make_timestamp ();
+
+ sprintf (buffer, "%.20s ? %lu %lu", pfx->what, pfx->offset,
+ pfx->total);
+ write_status_text (STATUS_PROGRESS, buffer);
+ }
+ else if (control == IOBUFCTRL_UNDERFLOW)
+ {
+ u32 timestamp = make_timestamp ();
+ int len = iobuf_read (a, buf, *ret_len);
+
+ if (len >= 0)
+ {
+ pfx->offset += len;
+ *ret_len = len;
+ }
+ else
+ {
+ *ret_len = 0;
+ rc = -1;
+ }
+ if ((len == -1 && pfx->offset != pfx->last)
+ || timestamp - pfx->last_time > 0)
+ {
+ char buffer[50];
+
+ sprintf (buffer, "%.20s ? %lu %lu", pfx->what, pfx->offset,
+ pfx->total);
+ write_status_text (STATUS_PROGRESS, buffer);
+
+ pfx->last = pfx->offset;
+ pfx->last_time = timestamp;
+ }
+ }
+ else if (control == IOBUFCTRL_DESC)
+ *(char**)buf = "progress_filter";
+ return rc;
+}
+
+void
+handle_progress (progress_filter_context_t *pfx, IOBUF inp, char *name)
+{
+ off_t filesize = 0;
+
+ if (!opt.enable_progress_filter)
+ return;
+
+ if (!is_status_enabled ())
+ return;
+
+ if (name)
+ filesize = iobuf_get_filelength (inp);
+ else if (opt.set_filesize)
+ filesize = opt.set_filesize;
+
+ /* register the progress filter */
+ pfx->what = name ? name : "stdin";
+ pfx->total = filesize;
+ iobuf_push_filter (inp, progress_filter, pfx);
+}
diff --git a/g10/sign.c b/g10/sign.c
index 9dad9b300..4463f66f5 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -631,6 +631,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
compress_filter_context_t zfx;
md_filter_context_t mfx;
text_filter_context_t tfx;
+ progress_filter_context_t pfx;
encrypt_filter_context_t efx;
IOBUF inp = NULL, out = NULL;
PACKET pkt;
@@ -677,11 +678,15 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
/* prepare iobufs */
if( multifile ) /* have list of filenames */
inp = NULL; /* we do it later */
- else if( !(inp = iobuf_open(fname)) ) {
- log_error("can't open %s: %s\n", fname? fname: "[stdin]",
- strerror(errno) );
- rc = G10ERR_OPEN_FILE;
- goto leave;
+ else {
+ if( !(inp = iobuf_open(fname)) ) {
+ log_error("can't open %s: %s\n", fname? fname: "[stdin]",
+ strerror(errno) );
+ rc = G10ERR_OPEN_FILE;
+ goto leave;
+ }
+
+ handle_progress (&pfx, inp, fname);
}
if( outfile ) {
@@ -819,6 +824,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
rc = G10ERR_OPEN_FILE;
goto leave;
}
+ handle_progress (&pfx, inp, sl->d);
if( opt.verbose )
fprintf(stderr, " `%s'", sl->d );
if(opt.textmode)
@@ -882,6 +888,7 @@ int
clearsign_file( const char *fname, STRLIST locusr, const char *outfile )
{
armor_filter_context_t afx;
+ progress_filter_context_t pfx;
MD_HANDLE textmd = NULL;
IOBUF inp = NULL, out = NULL;
PACKET pkt;
@@ -919,6 +926,7 @@ clearsign_file( const char *fname, STRLIST locusr, const char *outfile )
rc = G10ERR_OPEN_FILE;
goto leave;
}
+ handle_progress (&pfx, inp, fname);
if( outfile ) {
if( !(out = iobuf_create( outfile )) ) {
@@ -1014,6 +1022,7 @@ int
sign_symencrypt_file (const char *fname, STRLIST locusr)
{
armor_filter_context_t afx;
+ progress_filter_context_t pfx;
compress_filter_context_t zfx;
md_filter_context_t mfx;
text_filter_context_t tfx;
@@ -1049,6 +1058,7 @@ sign_symencrypt_file (const char *fname, STRLIST locusr)
rc = G10ERR_OPEN_FILE;
goto leave;
}
+ handle_progress (&pfx, inp, fname);
/* prepare key */
s2k = m_alloc_clear( sizeof *s2k );
diff --git a/g10/verify.c b/g10/verify.c
index 7ab20c140..705a45746 100644
--- a/g10/verify.c
+++ b/g10/verify.c
@@ -56,6 +56,7 @@ verify_signatures( int nfiles, char **files )
{
IOBUF fp;
armor_filter_context_t afx;
+ progress_filter_context_t pfx;
const char *sigfile;
int i, rc;
STRLIST sl;
@@ -94,6 +95,7 @@ verify_signatures( int nfiles, char **files )
log_error(_("can't open `%s'\n"), print_fname_stdin(sigfile));
return G10ERR_OPEN_FILE;
}
+ handle_progress (&pfx, fp, sigfile);
if( !opt.no_armor && use_armor_filter( fp ) )
iobuf_push_filter( fp, armor_filter, &afx );
@@ -130,6 +132,7 @@ verify_one_file( const char *name )
{
IOBUF fp;
armor_filter_context_t afx;
+ progress_filter_context_t pfx;
int rc;
print_file_status( STATUS_FILE_START, name, 1 );
@@ -139,6 +142,7 @@ verify_one_file( const char *name )
log_error(_("can't open `%s'\n"), print_fname_stdin(name));
return G10ERR_OPEN_FILE;
}
+ handle_progress (&pfx, fp, name);
if( !opt.no_armor ) {
if( use_armor_filter( fp ) ) {