aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2003-11-15 22:31:58 +0000
committerDavid Shaw <[email protected]>2003-11-15 22:31:58 +0000
commit995d71258998eb6ed80a08cb5ad8c8bd03f13afb (patch)
tree486e8ad5b1e39f5c2063d82f5555a395be86f4a8
parent* encode.c (encode_simple), sign.c (sign_symencrypt_file): Properly use (diff)
downloadgnupg-995d71258998eb6ed80a08cb5ad8c8bd03f13afb.tar.gz
gnupg-995d71258998eb6ed80a08cb5ad8c8bd03f13afb.zip
* 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.
Diffstat (limited to '')
-rw-r--r--g10/ChangeLog5
-rw-r--r--g10/compress-bz2.c16
-rw-r--r--g10/compress.c13
-rw-r--r--g10/encode.c11
-rw-r--r--g10/export.c4
-rw-r--r--g10/g10.c49
-rw-r--r--g10/misc.c8
-rw-r--r--g10/options.h5
-rw-r--r--g10/sign.c8
9 files changed, 67 insertions, 52 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index c0518ad65..7577b9273 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,5 +1,10 @@
2003-11-15 David Shaw <[email protected]>
+ * 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):
Properly use default_compress_algo (--compress-algo, followed by
the highest --personal-compress-preference, followed by ZIP) to
diff --git a/g10/compress-bz2.c b/g10/compress-bz2.c
index a8497c154..d1ad7326e 100644
--- a/g10/compress-bz2.c
+++ b/g10/compress-bz2.c
@@ -30,10 +30,10 @@
#include "options.h"
/* 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
- bug needs to be fixed. I tried to have one set of functions that
- could do ZIP, ZLIB, and BZIP2, but it became dangerously unreadable
- with #ifdefs and if(algo) -dshaw */
+ 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 functions that could
+ do ZIP, ZLIB, and BZIP2, but it became dangerously unreadable with
+ #ifdefs and if(algo) -dshaw */
static void
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 level;
- if( opt.compress >= 0 && opt.compress <= 9 )
- level = opt.compress;
- else if( opt.compress == -1 )
+ if( opt.bz2_compress_level >= 0 && opt.bz2_compress_level <= 9 )
+ level = opt.bz2_compress_level;
+ else if( opt.bz2_compress_level == -1 )
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;
else
{
diff --git a/g10/compress.c b/g10/compress.c
index 80878835a..c4282155a 100644
--- a/g10/compress.c
+++ b/g10/compress.c
@@ -20,7 +20,7 @@
*/
/* 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
functions that could do ZIP, ZLIB, and BZIP2, but it became
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);
#endif
- if( opt.compress >= 0 && opt.compress <= 9 )
- level = opt.compress;
- else if( opt.compress == -1 )
+ if( opt.compress_level >= 0 && opt.compress_level <= 9 )
+ level = opt.compress_level;
+ else if( opt.compress_level == -1 )
level = Z_DEFAULT_COMPRESSION;
- else if( opt.compress == 10 ) /* remove this ! */
+ else if( opt.compress_level == 10 ) /* remove this ! */
level = 0;
else {
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)
{
+ case COMPRESS_ALGO_NONE:
+ break;
+
case COMPRESS_ALGO_ZIP:
case COMPRESS_ALGO_ZLIB:
iobuf_push_filter2(out,compress_filter,zfx,rel);
diff --git a/g10/encode.c b/g10/encode.c
index b6a776d4a..95df2f682 100644
--- a/g10/encode.c
+++ b/g10/encode.c
@@ -220,8 +220,8 @@ encode_simple( const char *filename, int mode, int use_seskey )
cfx.dek->use_mdc=use_mdc(NULL,cfx.dek->algo);
}
- if (opt.compress == -1 && cfx.dek && cfx.dek->use_mdc &&
- is_file_compressed(filename, &rc))
+ if (do_compress && cfx.dek && cfx.dek->use_mdc
+ && is_file_compressed(filename, &rc))
{
if (opt.verbose)
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;
progress_filter_context_t pfx;
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( &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
ciphertext attacks. */
- if (opt.compress == -1 && cfx.dek->use_mdc &&
- is_file_compressed(filename, &rc2) )
+ if (do_compress && cfx.dek->use_mdc && is_file_compressed(filename, &rc2) )
{
if (opt.verbose)
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 */
if( do_compress ) {
- int compr_algo = opt.def_compress_algo;
+ int compr_algo = opt.compress_algo;
if(compr_algo==-1)
{
diff --git a/g10/export.c b/g10/export.c
index 1545fafcd..d98257144 100644
--- a/g10/export.c
+++ b/g10/export.c
@@ -113,8 +113,8 @@ do_export( STRLIST users, int secret, unsigned int options )
afx.what = secret?5:1;
iobuf_push_filter( out, armor_filter, &afx );
}
- if( opt.compress_keys && opt.compress )
- push_compress_filter(out,&zfx,opt.def_compress_algo);
+ if( opt.compress_keys )
+ push_compress_filter(out,&zfx,default_compress_algo());
rc = do_export_stream( out, users, secret, NULL, options, &any );
if( rc || !any )
diff --git a/g10/g10.c b/g10/g10.c
index 5ce2f478e..69e3a1b49 100644
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -190,6 +190,8 @@ enum cmd_and_opt_values
oDigestAlgo,
oCertDigestAlgo,
oCompressAlgo,
+ oCompressLevel,
+ oBZ2CompressLevel,
oPasswdFD,
#ifdef __riscos__
oPasswdFile,
@@ -418,7 +420,9 @@ static ARGPARSE_OPTS opts[] = {
{ oHiddenEncryptTo, "hidden-encrypt-to", 2, "@" },
{ oNoEncryptTo, "no-encrypt-to", 0, "@" },
{ 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, "@"},
{ oTextmode, "textmode", 0, N_("use canonical text mode")},
{ oNoTextmode, "no-textmode", 0, "@"},
@@ -1161,7 +1165,7 @@ main( int argc, char **argv )
const char *trustdb_name = NULL;
char *def_cipher_string = NULL;
char *def_digest_string = NULL;
- char *def_compress_string = NULL;
+ char *compress_algo_string = NULL;
char *cert_digest_string = NULL;
char *s2k_cipher_string = NULL;
char *s2k_digest_string = NULL;
@@ -1195,12 +1199,12 @@ main( int argc, char **argv )
create_dotlock(NULL); /* register locking cleanup */
i18n_init();
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 */
opt.def_cipher_algo = 0;
opt.def_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_digest_algo = DIGEST_ALGO_SHA1;
#ifdef USE_CAST5
@@ -1657,7 +1661,7 @@ main( int argc, char **argv )
opt.def_cipher_algo = 0;
opt.def_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_digest_algo = DIGEST_ALGO_SHA1;
opt.s2k_cipher_algo = CIPHER_ALGO_3DES;
@@ -1780,7 +1784,12 @@ main( int argc, char **argv )
case oUser: /* store the local users */
add_to_strlist2( &locusr, pargs.r.ret_str, utf8_strings );
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:
pwfd = iobuf_translate_file_handle (pargs.r.ret_int, 0);
opt.use_agent = 0;
@@ -1816,12 +1825,12 @@ main( int argc, char **argv )
if(*pt=='\0')
{
- def_compress_string=m_alloc(strlen(pargs.r.ret_str)+2);
- strcpy(def_compress_string,"Z");
- strcat(def_compress_string,pargs.r.ret_str);
+ compress_algo_string=m_alloc(strlen(pargs.r.ret_str)+2);
+ strcpy(compress_algo_string,"Z");
+ strcat(compress_algo_string,pargs.r.ret_str);
}
else
- def_compress_string = m_strdup(pargs.r.ret_str);
+ compress_algo_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;
m_free(def_digest_string);
def_digest_string = m_strdup("md5");
- opt.def_compress_algo = 1;
+ opt.compress_algo = COMPRESS_ALGO_ZIP;
}
}
else if(PGP6)
@@ -2213,10 +2222,10 @@ main( int argc, char **argv )
if( check_digest_algo(opt.def_digest_algo) )
log_error(_("selected digest algorithm is invalid\n"));
}
- if( def_compress_string ) {
- opt.def_compress_algo = string_to_compress_algo(def_compress_string);
- m_free(def_compress_string); def_compress_string = NULL;
- if( check_compress_algo(opt.def_compress_algo) )
+ if( compress_algo_string ) {
+ opt.compress_algo = string_to_compress_algo(compress_algo_string);
+ m_free(compress_algo_string); compress_algo_string = NULL;
+ if( check_compress_algo(opt.compress_algo) )
log_error(_("selected compression algorithm is invalid\n"));
}
if( cert_digest_string ) {
@@ -2340,10 +2349,10 @@ main( int argc, char **argv )
badalg=digest_algo_to_string(opt.cert_digest_algo);
badtype=PREFTYPE_HASH;
}
- else if(opt.def_compress_algo!=-1
- && !algo_available(PREFTYPE_ZIP,opt.def_compress_algo,NULL))
+ else if(opt.compress_algo!=-1
+ && !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;
}
@@ -2400,10 +2409,6 @@ main( int argc, char **argv )
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 */
if( opt.textmode == 2 && !detached_sig && opt.armor && cmd == aSign )
cmd = aClearsign;
diff --git a/g10/misc.c b/g10/misc.c
index 49a84d905..5583787e8 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -575,6 +575,8 @@ string_to_compress_algo(const char *string)
{
if(ascii_strcasecmp(string,"uncompressed")==0)
return 0;
+ else if(ascii_strcasecmp(string,"none")==0)
+ return 0;
else if(ascii_strcasecmp(string,"zip")==0)
return 1;
else if(ascii_strcasecmp(string,"zlib")==0)
@@ -623,13 +625,13 @@ default_cipher_algo(void)
}
/* There is no default_digest_algo function, but see
- sign.c:hash_for */
+ sign.c:hash_for() */
int
default_compress_algo(void)
{
- if(opt.def_compress_algo!=-1)
- return opt.def_compress_algo;
+ if(opt.compress_algo!=-1)
+ return opt.compress_algo;
else if(opt.personal_compress_prefs)
return opt.personal_compress_prefs[0].value;
else
diff --git a/g10/options.h b/g10/options.h
index 64799361a..391adc862 100644
--- a/g10/options.h
+++ b/g10/options.h
@@ -42,7 +42,6 @@ struct {
int quiet;
unsigned debug;
int armor;
- int compress;
char *outfile;
int dry_run;
int list_only;
@@ -68,7 +67,9 @@ struct {
int disable_mdc;
int def_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;
char *def_recipient;
int def_recipient_self;
diff --git a/g10/sign.c b/g10/sign.c
index 17c1d2614..55ed2f198 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -836,9 +836,9 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
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(compr_algo==-1)
@@ -1180,8 +1180,8 @@ sign_symencrypt_file (const char *fname, STRLIST locusr)
/* Push the encryption filter */
iobuf_push_filter( out, cipher_filter, &cfx );
- /* Push the Zip filter */
- if (opt.compress && default_compress_algo())
+ /* Push the compress filter */
+ if (default_compress_algo())
push_compress_filter(out,&zfx,default_compress_algo());
/* Write the one-pass signature packets */