1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-03-11 22:52:47 +01:00

* options.h, g10.c (main), compress.c (init_compress), compress-bz2.c

(init_compress): Add --compress-level and --bzip2-compress-level.  -z sets
them both.  Change various callers.
This commit is contained in:
David Shaw 2003-11-15 22:31:58 +00:00
parent 3257edd4e4
commit 995d712589
9 changed files with 67 additions and 52 deletions

View File

@ -1,5 +1,10 @@
2003-11-15 David Shaw <dshaw@jabberwocky.com> 2003-11-15 David Shaw <dshaw@jabberwocky.com>
* options.h, g10.c (main), compress.c (init_compress),
compress-bz2.c (init_compress): Add --compress-level and
--bzip2-compress-level. -z sets them both. Change various
callers.
* encode.c (encode_simple), sign.c (sign_symencrypt_file): * encode.c (encode_simple), sign.c (sign_symencrypt_file):
Properly use default_compress_algo (--compress-algo, followed by Properly use default_compress_algo (--compress-algo, followed by
the highest --personal-compress-preference, followed by ZIP) to the highest --personal-compress-preference, followed by ZIP) to

View File

@ -30,10 +30,10 @@
#include "options.h" #include "options.h"
/* Note that the code in compress.c is nearly identical to the code /* Note that the code in compress.c is nearly identical to the code
here, so if you fix a bug here, look there to see if the matching here, so if you fix a bug here, look there to see if a matching bug
bug needs to be fixed. I tried to have one set of functions that needs to be fixed. I tried to have one set of functions that could
could do ZIP, ZLIB, and BZIP2, but it became dangerously unreadable do ZIP, ZLIB, and BZIP2, but it became dangerously unreadable with
with #ifdefs and if(algo) -dshaw */ #ifdefs and if(algo) -dshaw */
static void static void
init_compress( compress_filter_context_t *zfx, bz_stream *bzs ) init_compress( compress_filter_context_t *zfx, bz_stream *bzs )
@ -41,11 +41,11 @@ init_compress( compress_filter_context_t *zfx, bz_stream *bzs )
int rc; int rc;
int level; int level;
if( opt.compress >= 0 && opt.compress <= 9 ) if( opt.bz2_compress_level >= 0 && opt.bz2_compress_level <= 9 )
level = opt.compress; level = opt.bz2_compress_level;
else if( opt.compress == -1 ) else if( opt.bz2_compress_level == -1 )
level = 6; /* no particular reason, but it seems reasonable */ level = 6; /* no particular reason, but it seems reasonable */
else if( opt.compress == 10 ) /* remove this ! */ else if( opt.bz2_compress_level == 10 ) /* remove this ! */
level = 0; level = 0;
else else
{ {

View File

@ -20,7 +20,7 @@
*/ */
/* Note that the code in compress-bz2.c is nearly identical to the /* Note that the code in compress-bz2.c is nearly identical to the
code here, so if you fix a bug here, look there to see if the code here, so if you fix a bug here, look there to see if a
matching bug needs to be fixed. I tried to have one set of matching bug needs to be fixed. I tried to have one set of
functions that could do ZIP, ZLIB, and BZIP2, but it became functions that could do ZIP, ZLIB, and BZIP2, but it became
dangerously unreadable with #ifdefs and if(algo) -dshaw */ dangerously unreadable with #ifdefs and if(algo) -dshaw */
@ -60,11 +60,11 @@ init_compress( compress_filter_context_t *zfx, z_stream *zs )
zlib_initialized = riscos_load_module("ZLib", zlib_path, 1); zlib_initialized = riscos_load_module("ZLib", zlib_path, 1);
#endif #endif
if( opt.compress >= 0 && opt.compress <= 9 ) if( opt.compress_level >= 0 && opt.compress_level <= 9 )
level = opt.compress; level = opt.compress_level;
else if( opt.compress == -1 ) else if( opt.compress_level == -1 )
level = Z_DEFAULT_COMPRESSION; level = Z_DEFAULT_COMPRESSION;
else if( opt.compress == 10 ) /* remove this ! */ else if( opt.compress_level == 10 ) /* remove this ! */
level = 0; level = 0;
else { else {
log_error("invalid compression level; using default level\n"); log_error("invalid compression level; using default level\n");
@ -347,6 +347,9 @@ push_compress_filter2(IOBUF out,compress_filter_context_t *zfx,
switch(zfx->algo) switch(zfx->algo)
{ {
case COMPRESS_ALGO_NONE:
break;
case COMPRESS_ALGO_ZIP: case COMPRESS_ALGO_ZIP:
case COMPRESS_ALGO_ZLIB: case COMPRESS_ALGO_ZLIB:
iobuf_push_filter2(out,compress_filter,zfx,rel); iobuf_push_filter2(out,compress_filter,zfx,rel);

View File

@ -220,8 +220,8 @@ encode_simple( const char *filename, int mode, int use_seskey )
cfx.dek->use_mdc=use_mdc(NULL,cfx.dek->algo); cfx.dek->use_mdc=use_mdc(NULL,cfx.dek->algo);
} }
if (opt.compress == -1 && cfx.dek && cfx.dek->use_mdc && if (do_compress && cfx.dek && cfx.dek->use_mdc
is_file_compressed(filename, &rc)) && is_file_compressed(filename, &rc))
{ {
if (opt.verbose) if (opt.verbose)
log_info(_("`%s' already compressed\n"), filename); log_info(_("`%s' already compressed\n"), filename);
@ -438,7 +438,7 @@ encode_crypt( const char *filename, STRLIST remusr, int use_symkey )
text_filter_context_t tfx; text_filter_context_t tfx;
progress_filter_context_t pfx; progress_filter_context_t pfx;
PK_LIST pk_list,work_list; PK_LIST pk_list,work_list;
int do_compress = opt.compress && !RFC1991; int do_compress = opt.compress_algo && !RFC1991;
memset( &cfx, 0, sizeof cfx); memset( &cfx, 0, sizeof cfx);
memset( &afx, 0, sizeof afx); memset( &afx, 0, sizeof afx);
@ -534,8 +534,7 @@ encode_crypt( const char *filename, STRLIST remusr, int use_symkey )
not have a MDC to give some protection against chosen not have a MDC to give some protection against chosen
ciphertext attacks. */ ciphertext attacks. */
if (opt.compress == -1 && cfx.dek->use_mdc && if (do_compress && cfx.dek->use_mdc && is_file_compressed(filename, &rc2) )
is_file_compressed(filename, &rc2) )
{ {
if (opt.verbose) if (opt.verbose)
log_info(_("`%s' already compressed\n"), filename); log_info(_("`%s' already compressed\n"), filename);
@ -615,7 +614,7 @@ encode_crypt( const char *filename, STRLIST remusr, int use_symkey )
/* register the compress filter */ /* register the compress filter */
if( do_compress ) { if( do_compress ) {
int compr_algo = opt.def_compress_algo; int compr_algo = opt.compress_algo;
if(compr_algo==-1) if(compr_algo==-1)
{ {

View File

@ -113,8 +113,8 @@ do_export( STRLIST users, int secret, unsigned int options )
afx.what = secret?5:1; afx.what = secret?5:1;
iobuf_push_filter( out, armor_filter, &afx ); iobuf_push_filter( out, armor_filter, &afx );
} }
if( opt.compress_keys && opt.compress ) if( opt.compress_keys )
push_compress_filter(out,&zfx,opt.def_compress_algo); push_compress_filter(out,&zfx,default_compress_algo());
rc = do_export_stream( out, users, secret, NULL, options, &any ); rc = do_export_stream( out, users, secret, NULL, options, &any );
if( rc || !any ) if( rc || !any )

View File

@ -190,6 +190,8 @@ enum cmd_and_opt_values
oDigestAlgo, oDigestAlgo,
oCertDigestAlgo, oCertDigestAlgo,
oCompressAlgo, oCompressAlgo,
oCompressLevel,
oBZ2CompressLevel,
oPasswdFD, oPasswdFD,
#ifdef __riscos__ #ifdef __riscos__
oPasswdFile, oPasswdFile,
@ -418,7 +420,9 @@ static ARGPARSE_OPTS opts[] = {
{ oHiddenEncryptTo, "hidden-encrypt-to", 2, "@" }, { oHiddenEncryptTo, "hidden-encrypt-to", 2, "@" },
{ oNoEncryptTo, "no-encrypt-to", 0, "@" }, { oNoEncryptTo, "no-encrypt-to", 0, "@" },
{ oUser, "local-user",2, N_("use this user-id to sign or decrypt")}, { oUser, "local-user",2, N_("use this user-id to sign or decrypt")},
{ oCompress, NULL, 1, N_("|N|set compress level N (0 disables)") }, { oCompress, NULL, 1, N_("|N|set compress level N (0 disables)") },
{ oCompressLevel, "compress-level", 1, "@" },
{ oBZ2CompressLevel, "bz2-compress-level", 1, "@" },
{ oTextmodeShort, NULL, 0, "@"}, { oTextmodeShort, NULL, 0, "@"},
{ oTextmode, "textmode", 0, N_("use canonical text mode")}, { oTextmode, "textmode", 0, N_("use canonical text mode")},
{ oNoTextmode, "no-textmode", 0, "@"}, { oNoTextmode, "no-textmode", 0, "@"},
@ -1161,7 +1165,7 @@ main( int argc, char **argv )
const char *trustdb_name = NULL; const char *trustdb_name = NULL;
char *def_cipher_string = NULL; char *def_cipher_string = NULL;
char *def_digest_string = NULL; char *def_digest_string = NULL;
char *def_compress_string = NULL; char *compress_algo_string = NULL;
char *cert_digest_string = NULL; char *cert_digest_string = NULL;
char *s2k_cipher_string = NULL; char *s2k_cipher_string = NULL;
char *s2k_digest_string = NULL; char *s2k_digest_string = NULL;
@ -1195,12 +1199,12 @@ main( int argc, char **argv )
create_dotlock(NULL); /* register locking cleanup */ create_dotlock(NULL); /* register locking cleanup */
i18n_init(); i18n_init();
opt.command_fd = -1; /* no command fd */ opt.command_fd = -1; /* no command fd */
opt.compress = -1; /* defaults to standard compress level */ opt.compress_level = -1; /* defaults to standard compress level */
/* note: if you change these lines, look at oOpenPGP */ /* note: if you change these lines, look at oOpenPGP */
opt.def_cipher_algo = 0; opt.def_cipher_algo = 0;
opt.def_digest_algo = 0; opt.def_digest_algo = 0;
opt.cert_digest_algo = 0; opt.cert_digest_algo = 0;
opt.def_compress_algo = -1; opt.compress_algo = -1; /* defaults to DEFAULT_COMPRESS_ALGO */
opt.s2k_mode = 3; /* iterated+salted */ opt.s2k_mode = 3; /* iterated+salted */
opt.s2k_digest_algo = DIGEST_ALGO_SHA1; opt.s2k_digest_algo = DIGEST_ALGO_SHA1;
#ifdef USE_CAST5 #ifdef USE_CAST5
@ -1657,7 +1661,7 @@ main( int argc, char **argv )
opt.def_cipher_algo = 0; opt.def_cipher_algo = 0;
opt.def_digest_algo = 0; opt.def_digest_algo = 0;
opt.cert_digest_algo = 0; opt.cert_digest_algo = 0;
opt.def_compress_algo = -1; opt.compress_algo = -1;
opt.s2k_mode = 3; /* iterated+salted */ opt.s2k_mode = 3; /* iterated+salted */
opt.s2k_digest_algo = DIGEST_ALGO_SHA1; opt.s2k_digest_algo = DIGEST_ALGO_SHA1;
opt.s2k_cipher_algo = CIPHER_ALGO_3DES; opt.s2k_cipher_algo = CIPHER_ALGO_3DES;
@ -1780,7 +1784,12 @@ main( int argc, char **argv )
case oUser: /* store the local users */ case oUser: /* store the local users */
add_to_strlist2( &locusr, pargs.r.ret_str, utf8_strings ); add_to_strlist2( &locusr, pargs.r.ret_str, utf8_strings );
break; break;
case oCompress: opt.compress = pargs.r.ret_int; break; case oCompress:
/* this is the -z command line option */
opt.compress_level = opt.bz2_compress_level = pargs.r.ret_int;
break;
case oCompressLevel: opt.compress_level = pargs.r.ret_int; break;
case oBZ2CompressLevel: opt.bz2_compress_level = pargs.r.ret_int; break;
case oPasswdFD: case oPasswdFD:
pwfd = iobuf_translate_file_handle (pargs.r.ret_int, 0); pwfd = iobuf_translate_file_handle (pargs.r.ret_int, 0);
opt.use_agent = 0; opt.use_agent = 0;
@ -1816,12 +1825,12 @@ main( int argc, char **argv )
if(*pt=='\0') if(*pt=='\0')
{ {
def_compress_string=m_alloc(strlen(pargs.r.ret_str)+2); compress_algo_string=m_alloc(strlen(pargs.r.ret_str)+2);
strcpy(def_compress_string,"Z"); strcpy(compress_algo_string,"Z");
strcat(def_compress_string,pargs.r.ret_str); strcat(compress_algo_string,pargs.r.ret_str);
} }
else else
def_compress_string = m_strdup(pargs.r.ret_str); compress_algo_string = m_strdup(pargs.r.ret_str);
} }
break; break;
case oCertDigestAlgo: cert_digest_string = m_strdup(pargs.r.ret_str); break; case oCertDigestAlgo: cert_digest_string = m_strdup(pargs.r.ret_str); break;
@ -2173,7 +2182,7 @@ main( int argc, char **argv )
opt.ask_cert_expire = 0; opt.ask_cert_expire = 0;
m_free(def_digest_string); m_free(def_digest_string);
def_digest_string = m_strdup("md5"); def_digest_string = m_strdup("md5");
opt.def_compress_algo = 1; opt.compress_algo = COMPRESS_ALGO_ZIP;
} }
} }
else if(PGP6) else if(PGP6)
@ -2213,10 +2222,10 @@ main( int argc, char **argv )
if( check_digest_algo(opt.def_digest_algo) ) if( check_digest_algo(opt.def_digest_algo) )
log_error(_("selected digest algorithm is invalid\n")); log_error(_("selected digest algorithm is invalid\n"));
} }
if( def_compress_string ) { if( compress_algo_string ) {
opt.def_compress_algo = string_to_compress_algo(def_compress_string); opt.compress_algo = string_to_compress_algo(compress_algo_string);
m_free(def_compress_string); def_compress_string = NULL; m_free(compress_algo_string); compress_algo_string = NULL;
if( check_compress_algo(opt.def_compress_algo) ) if( check_compress_algo(opt.compress_algo) )
log_error(_("selected compression algorithm is invalid\n")); log_error(_("selected compression algorithm is invalid\n"));
} }
if( cert_digest_string ) { if( cert_digest_string ) {
@ -2340,10 +2349,10 @@ main( int argc, char **argv )
badalg=digest_algo_to_string(opt.cert_digest_algo); badalg=digest_algo_to_string(opt.cert_digest_algo);
badtype=PREFTYPE_HASH; badtype=PREFTYPE_HASH;
} }
else if(opt.def_compress_algo!=-1 else if(opt.compress_algo!=-1
&& !algo_available(PREFTYPE_ZIP,opt.def_compress_algo,NULL)) && !algo_available(PREFTYPE_ZIP,opt.compress_algo,NULL))
{ {
badalg=compress_algo_to_string(opt.def_compress_algo); badalg=compress_algo_to_string(opt.compress_algo);
badtype=PREFTYPE_ZIP; badtype=PREFTYPE_ZIP;
} }
@ -2400,10 +2409,6 @@ main( int argc, char **argv )
g10_opt_verbose = opt.verbose; g10_opt_verbose = opt.verbose;
} }
/* Compression algorithm 0 means no compression at all */
if( opt.def_compress_algo == 0)
opt.compress = 0;
/* kludge to let -sat generate a clear text signature */ /* kludge to let -sat generate a clear text signature */
if( opt.textmode == 2 && !detached_sig && opt.armor && cmd == aSign ) if( opt.textmode == 2 && !detached_sig && opt.armor && cmd == aSign )
cmd = aClearsign; cmd = aClearsign;

View File

@ -575,6 +575,8 @@ string_to_compress_algo(const char *string)
{ {
if(ascii_strcasecmp(string,"uncompressed")==0) if(ascii_strcasecmp(string,"uncompressed")==0)
return 0; return 0;
else if(ascii_strcasecmp(string,"none")==0)
return 0;
else if(ascii_strcasecmp(string,"zip")==0) else if(ascii_strcasecmp(string,"zip")==0)
return 1; return 1;
else if(ascii_strcasecmp(string,"zlib")==0) else if(ascii_strcasecmp(string,"zlib")==0)
@ -623,13 +625,13 @@ default_cipher_algo(void)
} }
/* There is no default_digest_algo function, but see /* There is no default_digest_algo function, but see
sign.c:hash_for */ sign.c:hash_for() */
int int
default_compress_algo(void) default_compress_algo(void)
{ {
if(opt.def_compress_algo!=-1) if(opt.compress_algo!=-1)
return opt.def_compress_algo; return opt.compress_algo;
else if(opt.personal_compress_prefs) else if(opt.personal_compress_prefs)
return opt.personal_compress_prefs[0].value; return opt.personal_compress_prefs[0].value;
else else

View File

@ -42,7 +42,6 @@ struct {
int quiet; int quiet;
unsigned debug; unsigned debug;
int armor; int armor;
int compress;
char *outfile; char *outfile;
int dry_run; int dry_run;
int list_only; int list_only;
@ -68,7 +67,9 @@ struct {
int disable_mdc; int disable_mdc;
int def_digest_algo; int def_digest_algo;
int cert_digest_algo; int cert_digest_algo;
int def_compress_algo; int compress_algo;
int compress_level;
int bz2_compress_level;
const char *def_secret_key; const char *def_secret_key;
char *def_recipient; char *def_recipient;
int def_recipient_self; int def_recipient_self;

View File

@ -836,9 +836,9 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
iobuf_push_filter( out, encrypt_filter, &efx ); iobuf_push_filter( out, encrypt_filter, &efx );
} }
if( opt.compress && !outfile && ( !detached || opt.compress_sigs) ) if( opt.compress_algo && !outfile && ( !detached || opt.compress_sigs) )
{ {
int compr_algo=opt.def_compress_algo; int compr_algo=opt.compress_algo;
/* If not forced by user */ /* If not forced by user */
if(compr_algo==-1) if(compr_algo==-1)
@ -1180,8 +1180,8 @@ sign_symencrypt_file (const char *fname, STRLIST locusr)
/* Push the encryption filter */ /* Push the encryption filter */
iobuf_push_filter( out, cipher_filter, &cfx ); iobuf_push_filter( out, cipher_filter, &cfx );
/* Push the Zip filter */ /* Push the compress filter */
if (opt.compress && default_compress_algo()) if (default_compress_algo())
push_compress_filter(out,&zfx,default_compress_algo()); push_compress_filter(out,&zfx,default_compress_algo());
/* Write the one-pass signature packets */ /* Write the one-pass signature packets */