Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Catching up to 2440bis-09. Bzip2 was supported.

  • Loading branch information...
commit 1af1c15153a6af5e00f15ca6456cb920b2422636 1 parent 5fc7016
@kazu-yamamoto authored
View
4 CHANGES
@@ -1,5 +1,9 @@
Change Log
+0.20 2003/12/08
+
+* Catching up to 2440bis-09. Bzip2 was supported.
+
0.19 2003/06/06
* Catching up to 2440bis-08.
View
106 buffer.c
@@ -16,7 +16,13 @@ private int decode_radix64(byte *, unsigned int);
#include <zlib.h>
private int inflate_gzip(byte *, unsigned int);
private z_stream z;
-#endif
+#endif /* HAVE_LIBZ */
+
+#ifdef HAVE_LIBBZ2
+#include <bzlib.h>
+private int inflate_bzip2(byte *, unsigned int);
+private bz_stream bz;
+#endif /* HAVE_LIBBZ2 */
#define NUL '\0'
#define CR '\r'
@@ -219,18 +225,18 @@ inflate_gzip(byte *p, unsigned int max)
err = inflate(&z, Z_SYNC_FLUSH);
if (err != Z_OK && err != Z_STREAM_END)
- warn_exit("inflate error (%d).", err);
+ warn_exit("zlib inflate error (%d).", err);
inflated = max - z.avail_out;
- if (old == z.avail_out)
+ if (old == z.avail_out && z.avail_in != 0)
break;
if (err == Z_STREAM_END) {
done = YES;
/* 8 bytes (crc and isize) are left. */
if (inflateEnd(&z) != Z_OK)
- warn_exit("inflateEnd error.");
+ warn_exit("zlib inflateEnd error.");
break;
}
}
@@ -239,6 +245,49 @@ inflate_gzip(byte *p, unsigned int max)
}
#endif /* HAVE_LIBZ */
+#ifdef HAVE_LIBBZ2
+private int
+inflate_bzip2(byte *p, unsigned int max)
+{
+ static int done = NO;
+ int err, size, inflated = 0, old;
+
+ if (done == YES) return 0;
+
+ bz.next_out = p;
+ bz.avail_out = max;
+
+ while (bz.avail_out != 0) {
+ if (bz.avail_in == 0) {
+ size = (*d_func2)(d_buf2, sizeof(d_buf2));
+ bz.next_in = d_buf2;
+ bz.avail_in = size;
+ }
+
+ old = bz.avail_out;
+ err = BZ2_bzDecompress(&bz);
+
+ if (err != BZ_OK && err != BZ_STREAM_END)
+ warn_exit("bzip2 BZ2_bzDecompress error (%d).", err);
+
+ inflated = max - bz.avail_out;
+
+ if (old == bz.avail_out && bz.avail_in != 0)
+ break;
+
+ if (err == BZ_STREAM_END) {
+ done = YES;
+ /* 8 bytes (crc and isize) are left. */
+ if (BZ2_bzDecompressEnd(&bz) != BZ_OK)
+ warn_exit("bzip2 BZ2_bzDecompressEnd error.");
+ break;
+ }
+ }
+
+ return inflated;
+}
+#endif /* HAVE_LIBBZ2 */
+
public int
Getc1(void)
{
@@ -302,44 +351,71 @@ set_binary(void)
public void
Compressed_Data_Packet(int len)
{
-#ifdef HAVE_LIBZ
+#if defined(HAVE_LIBZ) || defined(HAVE_LIBBZ2)
unsigned int alg = Getc();
int err = Z_OK;
+ private int (*func)(byte *, unsigned int);
comp_algs(alg);
+#ifdef HAVE_LIBZ
z.zalloc = (alloc_func)0;
z.zfree = (free_func)0;
z.opaque = (voidpf)0;
+#endif /* HAVE_LIBZ */
+#ifdef HAVE_LIBBZ2
+ bz.bzalloc = (void *)0;
+ bz.bzfree = (void *)0;
+ bz.opaque = (void *)0;
+#endif /* HAVE_LIBBZ2 */
/*
* 0 uncompressed
- * 1 ZIP 1951 without zlib header
+ * 1 ZIP without zlib header (RFC 1951)
* inflateInit2 (strm, -13)
- * 2 ZLIB 1950 with zlib header
+ * 2 ZLIB with zlib header (RFC 1950)
* inflateInit (strm)
+ * 3 BZIP2 (http://sources.redhat.com/bzip2/)
*/
switch (alg) {
case 0:
return;
+#ifdef HAVE_LIBZ
case 1:
err = inflateInit2(&z, -13);
+ if (err != Z_OK) warn_exit("zlib inflateInit error.");
+ func = inflate_gzip;
break;
case 2:
err = inflateInit(&z);
+ if (err != Z_OK) warn_exit("zlib inflateInit error.");
+ func = inflate_gzip;
+ break;
+#endif /* HAVE_LIBZ */
+#ifdef HAVE_LIBBZ2
+ case 3:
+ err = BZ2_bzDecompressInit(&bz, 0, 0);
+ if (err != BZ_OK) warn_exit("bzip2 BZ2_bzDecompressInit error.");
+ func = inflate_bzip2;
break;
+#endif /* HAVE_LIBBZ2 */
default:
warn_exit("unknown compress algorithm.");
}
- if (err != Z_OK)
- warn_exit("inflateInit error.");
-
+#ifdef HAVE_LIBZ
z.next_in = d_buf2;
z.avail_in = AVAIL_COUNT;
z.next_out = 0;
z.avail_out = sizeof(d_buf2);
+#endif /* HAVE_LIBZ */
+#ifdef HAVE_LIBBZ2
+ bz.next_in = d_buf2;
+ bz.avail_in = AVAIL_COUNT;
+ bz.next_out = 0;
+ bz.avail_out = sizeof(d_buf2);
+#endif /* HAVE_LIBBZ2 */
memcpy(d_buf2, NEXT_IN, AVAIL_COUNT);
AVAIL_COUNT = 0;
@@ -347,16 +423,16 @@ Compressed_Data_Packet(int len)
if (d_func1 == NULL) {
d_func1 = NULL;
d_func2 = read_binary;
- d_func3 = inflate_gzip;
+ d_func3 = func;
} else {
d_func1 = read_radix64;
d_func2 = decode_radix64;
- d_func3 = inflate_gzip;
+ d_func3 = func;
}
-#else /* HAVE_LIBZ */
+#else /* defined(HAVE_LIBZ) || defined(HAVE_LIBBZ2) */
comp_algs(Getc());
- warn_exit("can't uncompress without zlib.");
-#endif /* HAVE_LIBZ */
+ warn_exit("can't uncompress without zlib/bzip2.");
+#endif /* defined(HAVE_LIBZ) || defined(HAVE_LIBBZ2) */
}
/*
View
3  config.h.in
@@ -13,6 +13,9 @@
/* Define if you have the z library (-lz). */
#undef HAVE_LIBZ
+/* Define if you have the z library (-lbz2). */
+#undef HAVE_LIBBZ2
+
/* Define if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
View
90 configure
@@ -2123,9 +2123,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
-echo "$as_me:$LINENO: checking for main in -lz" >&5
-echo $ECHO_N "checking for main in -lz... $ECHO_C" >&6
-if test "${ac_cv_lib_z_main+set}" = set; then
+echo "$as_me:$LINENO: checking for inflate in -lz" >&5
+echo $ECHO_N "checking for inflate in -lz... $ECHO_C" >&6
+if test "${ac_cv_lib_z_inflate+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_check_lib_save_LIBS=$LIBS
@@ -2138,11 +2138,17 @@ cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
-
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char inflate ();
int
main ()
{
-main ();
+inflate ();
;
return 0;
}
@@ -2159,19 +2165,19 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
- ac_cv_lib_z_main=yes
+ ac_cv_lib_z_inflate=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
-ac_cv_lib_z_main=no
+ac_cv_lib_z_inflate=no
fi
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
-echo "$as_me:$LINENO: result: $ac_cv_lib_z_main" >&5
-echo "${ECHO_T}$ac_cv_lib_z_main" >&6
-if test $ac_cv_lib_z_main = yes; then
+echo "$as_me:$LINENO: result: $ac_cv_lib_z_inflate" >&5
+echo "${ECHO_T}$ac_cv_lib_z_inflate" >&6
+if test $ac_cv_lib_z_inflate = yes; then
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBZ 1
_ACEOF
@@ -2181,6 +2187,70 @@ _ACEOF
fi
+echo "$as_me:$LINENO: checking for BZ2_bzBuffToBuffDecompress in -lbz2" >&5
+echo $ECHO_N "checking for BZ2_bzBuffToBuffDecompress in -lbz2... $ECHO_C" >&6
+if test "${ac_cv_lib_bz2_BZ2_bzBuffToBuffDecompress+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lbz2 $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char BZ2_bzBuffToBuffDecompress ();
+int
+main ()
+{
+BZ2_bzBuffToBuffDecompress ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_lib_bz2_BZ2_bzBuffToBuffDecompress=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_bz2_BZ2_bzBuffToBuffDecompress=no
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_bz2_BZ2_bzBuffToBuffDecompress" >&5
+echo "${ECHO_T}$ac_cv_lib_bz2_BZ2_bzBuffToBuffDecompress" >&6
+if test $ac_cv_lib_bz2_BZ2_bzBuffToBuffDecompress = yes; then
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBBZ2 1
+_ACEOF
+
+ LIBS="-lbz2 $LIBS"
+
+fi
+
+
ac_config_headers="$ac_config_headers config.h"
ac_ext=c
View
4 configure.in
@@ -5,8 +5,8 @@ dnl Checks for programs.
dnl AC_PROG_INSTALL
dnl Checks for libraries.
-dnl Replace `main' with a function in -lz:
-AC_CHECK_LIB(z, main)
+AC_CHECK_LIB(z, inflate)
+AC_CHECK_LIB(bz2, BZ2_bzBuffToBuffDecompress)
dnl Checks for header files.
AC_CONFIG_HEADER(config.h)
View
2  pgpdump.c
@@ -13,7 +13,7 @@ int mflag;
int pflag;
int uflag;
-private char *pgpdump_version = "0.19, Copyright (C) 1998-2003 Kazu Yamamoto";
+private char *pgpdump_version = "0.20, Copyright (C) 1998-2003 Kazu Yamamoto";
private char *prog;
private void usage(void);
View
1  types.c
@@ -135,6 +135,7 @@ COMP_ALGS[] = {
"Uncompressed(comp 0)",
"ZIP <RFC1951>(comp 1)",
"ZLIB <RFC1950>(comp 2)",
+ "BZip2(comp 3)",
};
#define COMP_ALGS_NUM (sizeof(COMP_ALGS) / sizeof(char *))
Please sign in to comment.
Something went wrong with that request. Please try again.