From d739d1c9b10c7a70fdd502083f05ecde5ac74f7e Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 15 Apr 2003 15:49:41 +0000 Subject: [PATCH] * g10.c, options.h: New option --enable-progress-filter. * progress.c (handle_progress): Make use of it. --- g10/ChangeLog | 31 +++++++++++++++++++++++++++++++ g10/Makefile.am | 3 +++ g10/decrypt.c | 7 +++++++ g10/encode.c | 6 ++++++ g10/filter.h | 14 +++++++++++++- g10/g10.c | 6 +++++- g10/main.h | 2 +- g10/openfile.c | 7 +++++-- g10/options.h | 4 +++- g10/plaintext.c | 15 ++++++++++++--- g10/progress.c | 3 +++ g10/sign.c | 20 +++++++++++++++----- g10/verify.c | 4 ++++ 13 files changed, 108 insertions(+), 14 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index 5a6b97a71..c1be598ff 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,34 @@ +2003-04-15 Werner Koch + + * g10.c, options.h: New option --enable-progress-filter. + * progress.c (handle_progress): Make use of it. + +2003-04-15 Marcus Brinkmann + + * 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-15 Werner Koch + + * Makefile.am (AM_CFLAGS): Don't set GNUPG_LIBEXECDIR for Windows; + it defined in g10defs.h. + 2003-04-10 Werner Koch * passphrase.c (read_passphrase_from_fd): Do a dummy read if the diff --git a/g10/Makefile.am b/g10/Makefile.am index 75f0010e0..06d09483e 100644 --- a/g10/Makefile.am +++ b/g10/Makefile.am @@ -23,7 +23,9 @@ EXTRA_DIST = options.skel # it seems that we can't use this with automake 1.5 #OMIT_DEPENDENCIES = zlib.h zconf.h libexecdir = @libexecdir@/@PACKAGE@ +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 @@ -45,6 +47,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 b17eeb527..692b72966 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 b189bcf18..6b2c4f0f8 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 ); @@ -391,6 +394,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; @@ -427,6 +431,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 25db4d407..7e7170f16 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. * @@ -297,6 +297,7 @@ enum cmd_and_opt_values { aNull = 0, oNoStrict, oMangleDosFilenames, oNoMangleDosFilenames, + oEnableProgressFilter, aTest }; @@ -595,6 +596,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} }; @@ -1699,6 +1701,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 a55f4ed4e..29e5f2e95 100644 --- a/g10/main.h +++ b/g10/main.h @@ -138,7 +138,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 0abff5d5e..b1fd98ea9 100644 --- a/g10/openfile.c +++ b/g10/openfile.c @@ -266,7 +266,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; @@ -282,7 +282,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 9e597806d..5e1cb2e32 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. * @@ -179,6 +180,7 @@ struct { int show_keyring; struct groupitem *grouplist; int mangle_dos_filenames; + int enable_progress_filter; } opt; diff --git a/g10/plaintext.c b/g10/plaintext.c index b12fb0f11..b6a813c37 100644 --- a/g10/plaintext.c +++ b/g10/plaintext.c @@ -327,11 +327,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")); @@ -365,7 +370,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); @@ -382,15 +388,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")); @@ -405,6 +413,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 index 7313e29e5..19b78567e 100644 --- a/g10/progress.c +++ b/g10/progress.c @@ -102,3 +102,6 @@ handle_progress (progress_filter_context_t *pfx, IOBUF inp, char *name) pfx->total = filesize; iobuf_push_filter (inp, progress_filter, pfx); } + + + diff --git a/g10/sign.c b/g10/sign.c index 89a27de21..a62863b37 100644 --- a/g10/sign.c +++ b/g10/sign.c @@ -606,6 +606,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; @@ -652,11 +653,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 ) { @@ -794,6 +799,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) @@ -857,6 +863,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; @@ -894,6 +901,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 )) ) { @@ -989,6 +997,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; @@ -1024,6 +1033,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 ) ) {