aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>1999-06-01 14:08:57 +0000
committerWerner Koch <[email protected]>1999-06-01 14:08:57 +0000
commit3dddf602dd95863dab344486534874b4b561bd3d (patch)
tree322e4f944eb596a22af9fc4d98f2f000117672a7
parentSee ChangeLog: Mon May 31 19:41:10 CEST 1999 Werner Koch (diff)
downloadgnupg-3dddf602dd95863dab344486534874b4b561bd3d.tar.gz
gnupg-3dddf602dd95863dab344486534874b4b561bd3d.zip
See ChangeLog: Tue Jun 1 16:01:46 CEST 1999 Werner Koch
-rw-r--r--NEWS6
-rw-r--r--TODO3
-rw-r--r--acconfig.h3
-rw-r--r--cipher/rndlinux.c25
-rw-r--r--configure.in32
-rw-r--r--doc/manual.sgml91
-rw-r--r--g10/ChangeLog7
-rw-r--r--g10/g10.c3
-rw-r--r--g10/main.h1
-rw-r--r--g10/openfile.c32
-rw-r--r--g10/options.h1
-rw-r--r--g10/plaintext.c15
-rw-r--r--include/iobuf.h2
-rw-r--r--mpi/ChangeLog4
-rw-r--r--mpi/config.links4
-rw-r--r--mpi/mpiutil.c58
-rw-r--r--util/ChangeLog5
-rw-r--r--util/iobuf.c42
-rw-r--r--util/memory.c5
19 files changed, 270 insertions, 69 deletions
diff --git a/NEWS b/NEWS
index 774589a1a..17b4137d4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,12 @@
* New option -N to insert notations and a --set-policy-url.
- * New subcommand "delsig" in th edit menu.
+ * New subcommand "delsig" in the edit menu.
+ * The name of the output file is not anymore the one which is
+ embedded in the processed message, but the used filename with
+ the extension stripped. To revert to the old behaviour you can
+ use the option --use-embedded-filename.
Noteworthy changes in version 0.9.7
-----------------------------------
diff --git a/TODO b/TODO
index dbe27bffb..faba47d65 100644
--- a/TODO
+++ b/TODO
@@ -37,7 +37,6 @@ Nice to have
* replace the keyserver stuff either by a call to a specialized
utility and SOCKSify this utility.
* Do a real fix for bug #7 or document that it is a PGP 5 error.
- * clearsig: Keep lineendings while writing the output of a clearsig
* preferences of hash algorithms are not yet used.
* new menu to delete signatures and list signature in menu
* Replace the SIGUSR1 stuff by semaphores to avoid loss of a signal.
@@ -52,8 +51,6 @@ Nice to have
* the pubkey encrypt functions should do some sanity checks.
* dynload: implement the hint stuff.
* "gpg filename.tar.gz.asc" sollte wie mit --verify funktionieren (-sab).
- * Den Dateinamen aus der message nicht benutzen, sondern nur
- das gpg/asc strippen.
* for messages created with "-t", it might make sense to append the
verification status of the message to the output (i.e. write something to
the --output file and not only to stderr.
diff --git a/acconfig.h b/acconfig.h
index e3b4f29e7..de4e44f5a 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -70,6 +70,9 @@
/* and the real names of the random devices */
#undef NAME_OF_DEV_RANDOM
#undef NAME_OF_DEV_URANDOM
+/* Linux has an ioctl */
+#undef HAVE_DEV_RANDOM_IOCTL
+
#undef USE_DYNAMIC_LINKING
#undef HAVE_DL_DLOPEN
diff --git a/cipher/rndlinux.c b/cipher/rndlinux.c
index 8c591fbe8..78fee1567 100644
--- a/cipher/rndlinux.c
+++ b/cipher/rndlinux.c
@@ -33,6 +33,13 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#if 0
+ #ifdef HAVE_LINUX_RANDOM_H
+ #include <sys/ioctl.h>
+ #include <asm/types.h>
+ #include <linux/random.h>
+ #endif
+#endif
#include "types.h"
#include "util.h"
#include "ttyio.h"
@@ -48,6 +55,19 @@ static int open_device( const char *name, int minor );
static int gather_random( void (*add)(const void*, size_t, int), int requester,
size_t length, int level );
+#if 0
+#ifdef HAVE_DEV_RANDOM_IOCTL
+static ulong
+get_entropy_count( int fd )
+{
+ ulong count;
+
+ if( ioctl( fd, RNDGETENTCNT, &count ) == -1 )
+ g10_log_fatal("ioctl(RNDGETENTCNT) failed: %s\n", strerror(errno) );
+ return count;
+}
+#endif
+#endif
/****************
* Used to open the Linux and xBSD /dev/random devices
@@ -91,6 +111,11 @@ gather_random( void (*add)(const void*, size_t, int), int requester,
fd = fd_urandom;
}
+ #if 0
+ #ifdef HAVE_DEV_RANDOM_IOCTL
+ g10_log_info("entropy count of %d is %lu\n", fd, get_entropy_count(fd) );
+ #endif
+ #endif
while( length ) {
fd_set rfds;
struct timeval tv;
diff --git a/configure.in b/configure.in
index a67516c41..2faf657c2 100644
--- a/configure.in
+++ b/configure.in
@@ -330,20 +330,40 @@ if test "$ac_cv_header_sys_shm_h" = "yes"; then
AC_DEFINE(USE_SHM_COPROCESSING)
fi
+dnl
dnl check whether we have a random device
+dnl
if test "$try_dev_random" = yes ; then
-AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
-[if test -c "$NAME_OF_DEV_RANDOM" && test -c "$NAME_OF_DEV_URANDOM" ; then
- ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
-if test "$ac_cv_have_dev_random" = yes; then
- AC_DEFINE(HAVE_DEV_RANDOM)
-fi
+ AC_CACHE_CHECK(for random device, ac_cv_have_dev_random,
+ [if test -c "$NAME_OF_DEV_RANDOM" && test -c "$NAME_OF_DEV_URANDOM" ; then
+ ac_cv_have_dev_random=yes; else ac_cv_have_dev_random=no; fi])
+ if test "$ac_cv_have_dev_random" = yes; then
+ AC_DEFINE(HAVE_DEV_RANDOM)
+ fi
else
AC_MSG_CHECKING(for random device)
ac_cv_have_dev_random=no
AC_MSG_RESULT(has been disabled)
fi
+dnl
+dnl and whether this device supports ioctl
+dnl (Note, that we should do a real test here)
+dnl
+if test "$ac_cv_have_dev_random" = yes ; then
+ AC_CHECK_HEADERS(linux/random.h)
+ AC_CACHE_CHECK(for random device ioctl, ac_cv_have_dev_random_ioctl,
+ [ if test "$ac_cv_header_linux_random_h" = yes ; then
+ ac_cv_have_dev_random_ioctl=yes;
+ else
+ ac_cv_have_dev_random_ioctl=no;
+ fi
+ ])
+ if test "$ac_cv_have_dev_random_ioctl" = yes; then
+ AC_DEFINE(HAVE_DEV_RANDOM_IOCTL)
+ fi
+fi
+
dnl
dnl Figure out the default linkage mode for cipher modules
diff --git a/doc/manual.sgml b/doc/manual.sgml
index a604d5357..56e8e92b4 100644
--- a/doc/manual.sgml
+++ b/doc/manual.sgml
@@ -1,26 +1,44 @@
<!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
+<!entity gnupg "GnuPG">
+<!entity wwwgnu "http://www.gnu.org">
+<!entity wwwgnupg "http://www.gnupg.org">
]>
<book>
<bookinfo>
- <title>The GNU Privacy Guard</title>
+ <title>The GNU Privacy Guard Manual</title>
+ <titleabbrev>GnuPG-Man</titleabbrev>
+ <edition>v0.0.0</edition>
<authorgroup>
- <author> <firstname>Werner</firstname> <surname>Koch</surname>
- <affiliation><address><email>[email protected]</email></address>
- </affiliation>
+ <!-- Replace with your name and delete mine -->
+ <author>
+ <firstname>Joe</firstname>
+ <othername>D.</othername>
+ <surname>Foo</surname>
+ <authorblurb>
+ <para><email>joe@somewhere</email></para>
+ </authorblurb>
+ </author>
+ <author>
+ <firstname>Werner</firstname>
+ <surname>Koch</surname>
+ <authorblurb>
+ <para><email>[email protected]</email></para>
+ </authorblurb>
</author>
</authorgroup>
- <!-- <version>last modified: <date></version> -->
- <copyright><year>1998</year><year>1998</year>
+ <!-- note, it is possible to give more than 1 year -->
+ <copyright><year>1999</year>
<holder>Free Software Foundation, Inc.</holder>
</copyright>
+ <!-- We have to check, whether this is the right wording -->
<legalnotice>
- <para>This documentation is free software; you can redistribute
+ <para>This manual 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.</para>
- <para>This program is distributed in the hope that it will be
+ <para>This manual 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
@@ -32,61 +50,52 @@
MA 02111-1307 USA</para>
<para>For more details see the file COPYING in the source
- distribution of GNUPG.</para>
+ distribution of &gnupg;.</para>
</legalnotice>
</bookinfo>
+ <!-- Insert the table of contents -->
<toc></toc>
+<!--*******************************************
+ ********* the first chapter *************
+ *******************************************-->
<chapter id="intro">
<title>Introduction</title>
<sect1 id="feedback">
<title>Feedback</title>
+ <!-- Hope we can remove this ;-) -->
<para>Well, I'm German and I find it hard to express myself in
English. So if you find some phrases and/or words that I used
in a wrong way (and you will find them :-) ), please send me a
mail, to let me correct this. Please send me notes about
- typos, too.</para>
+ typos, too.
</sect1>
<sect1 id="whatis">
- <title>What is GNUPG</title>
- <para>GNUPG is a free data encryption and signing tool.
+ <title>What is &gnupg;</title>
+ <para><ulink url="&wwwgnupg;">&gnupg;</> is a tool for digital
+ encryption and signing;
+ it is part of the <ulink url="&wwwgnu;">GNU Project</>.
- <screen>
- <prompt/$/ <userinput>gpg --version</>
+ <para>It has these features:
+ <itemizedlist>
+ <listitem>
+ <para>Exciting feature 1
+ </listitem>
+ <listitem>
+ <para>Exciting feature 2
+ </listitem>
+ </itemizedlist>
- </screen>
+ <para>How to find out the version of &gnupg;
+ <screen>
+ <prompt/$/ <userinput>gpg --version</>
+ </screen>
</sect1>
</chapter>
-<reference>
- <title>Manual Pages</title>
- <partintro>
- <para>These are some short man(1) pages</para>
- </partintro>
- <refentry>
- <refmeta>
- <refentrytitle>gpg</refentrytitle>
- <manvolnum>1</manvolnum>
- <refmiscinfo class="tools">GNU Tools</refmiscinfo></refmiscinfo>
- </refmeta>
-
- <refsynopsisdiv>
- <synopsis>
- <command>gpg</command>
- <optional><parameter>options</parameter></optional>
- <replaceable class="parameter">file name</replaceable>
- </synopsis>
- <refpurpose>is the GNU tool for signing and encryption</>
- <refsect1>
- <title>Description</title>
- <para> </para>
- </refsect1>
- </refentry>
-</reference>
-
</book>
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 5096b94fa..f3a51cd4c 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,10 @@
+Tue Jun 1 16:01:46 CEST 1999 Werner Koch <[email protected]>
+
+ * openfile.c (make_outfile_name): New.
+ * plaintext.c (handle_plaintext): Outputfile is now the inputfile
+ without the suffix.
+ * g10.c: New option --use-embedded-filename
+
Mon May 31 19:41:10 CEST 1999 Werner Koch <[email protected]>
* g10.c (main): Fix for SHM init (Michael).
diff --git a/g10/g10.c b/g10/g10.c
index eb6d32ff3..acc3f3098 100644
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -144,6 +144,7 @@ enum cmd_and_opt_values { aNull = 0,
oRunAsShmCP,
oSetFilename,
oSetPolicyURL,
+ oUseEmbeddedFilename,
oComment,
oThrowKeyid,
oForceV3Sigs,
@@ -301,6 +302,7 @@ static ARGPARSE_OPTS opts[] = {
{ oEscapeFrom, "escape-from-lines", 0, "@" },
{ oLockOnce, "lock-once", 0, "@" },
{ oLoggerFD, "logger-fd",1, "@" },
+ { oUseEmbeddedFilename, "use-embedded-filename", 0, "@" },
{0} };
@@ -718,6 +720,7 @@ main( int argc, char **argv )
break;
case oSetFilename: opt.set_filename = pargs.r.ret_str; break;
case oSetPolicyURL: opt.set_policy_url = pargs.r.ret_str; break;
+ case oUseEmbeddedFilename: opt.use_embedded_filename = 1; break;
case oComment: opt.comment_string = pargs.r.ret_str; break;
case oThrowKeyid: opt.throw_keyid = 1; break;
case oForceV3Sigs: opt.force_v3_sigs = 1; break;
diff --git a/g10/main.h b/g10/main.h
index fa03d17a6..5889ccf71 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -96,6 +96,7 @@ int generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock );
/*-- openfile.c --*/
int overwrite_filep( const char *fname );
+char *make_outfile_name( const char *iname );
int open_outfile( const char *iname, int mode, IOBUF *a );
IOBUF open_sigfile( const char *iname );
void copy_options_file( const char *destdir );
diff --git a/g10/openfile.c b/g10/openfile.c
index e60520adb..af0ab3c1d 100644
--- a/g10/openfile.c
+++ b/g10/openfile.c
@@ -71,6 +71,36 @@ overwrite_filep( const char *fname )
/****************
+ * Strip know extensions from iname and return a newly allocated
+ * filename. Return NULL if we can't do that.
+ */
+char *
+make_outfile_name( const char *iname )
+{
+ size_t n;
+
+ if( (!iname || (*iname=='-' && !iname[1]) ))
+ return m_strdup("-");
+
+ #ifdef HAVE_DRIVE_LETTERS
+ #warning add case insensitive compare
+ #endif
+ n = strlen(iname);
+ if( n > 4 && ( !strcmp(iname+n-4,".gpg")
+ || !strcmp(iname+n-4,".sig")
+ || !strcmp(iname+n-4,".asc") ) ) {
+ char *buf = m_strdup( iname );
+ buf[n-4] = 0;
+ return buf;
+ }
+
+ log_error(_("%s: unknown suffix\n"), iname );
+ return NULL;
+}
+
+
+
+/****************
* Make an output filename for the inputfile INAME.
* Returns an IOBUF and an errorcode
* Mode 0 = use ".gpg"
@@ -108,6 +138,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
mode==2 ? ".sig" : ".gpg");
name = buf;
}
+
if( overwrite_filep( name ) ) {
if( !(*a = iobuf_create( name )) ) {
log_error(_("%s: can't create: %s\n"), name, strerror(errno) );
@@ -124,6 +155,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
}
+
/****************
* Try to open a file without the extension ".sig" or ".asc"
* Return NULL if such a file is not available.
diff --git a/g10/options.h b/g10/options.h
index d40f59fb0..57265f9e4 100644
--- a/g10/options.h
+++ b/g10/options.h
@@ -76,6 +76,7 @@ struct {
int interactive;
STRLIST notation_data;
const char *set_policy_url;
+ int use_embedded_filename;
} opt;
diff --git a/g10/plaintext.c b/g10/plaintext.c
index 000ede0c3..1edca16e5 100644
--- a/g10/plaintext.c
+++ b/g10/plaintext.c
@@ -63,6 +63,13 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
log_info(_("data not saved; use option \"--output\" to save it\n"));
nooutput = 1;
}
+ else if( !opt.use_embedded_filename ) {
+ fname = make_outfile_name( iobuf_get_real_fname(pt->buf) );
+ if( !fname ) {
+ rc = G10ERR_CREATE_FILE;
+ goto leave;
+ }
+ }
else {
fname = m_alloc( pt->namelen +1 );
memcpy( fname, pt->name, pt->namelen );
@@ -90,7 +97,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
if( pt->len ) {
assert( !clearsig );
- if( convert ) { // text mode
+ if( convert ) { /* text mode */
for( ; pt->len; pt->len-- ) {
if( (c = iobuf_get(pt->buf)) == -1 ) {
log_error("Problem reading source (%u bytes remaining)\n",
@@ -112,7 +119,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
}
}
- else { // binary mode
+ else { /* binary mode */
byte *buffer = m_alloc( 32768 );
while( pt->len ) {
int len = pt->len > 32768 ? 32768 : pt->len;
@@ -141,7 +148,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
}
else if( !clearsig ) {
- if( convert ) { // text mode
+ if( convert ) { /* text mode */
while( (c = iobuf_get(pt->buf)) != -1 ) {
if( mfx->md )
md_putc(mfx->md, c );
@@ -157,7 +164,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
}
}
- else { // binary mode
+ else { /* binary mode */
byte *buffer = m_alloc( 32768 );
for( ;; ) {
int len = iobuf_read( pt->buf, buffer, 32768 );
diff --git a/include/iobuf.h b/include/iobuf.h
index fb21badbc..363b09e5b 100644
--- a/include/iobuf.h
+++ b/include/iobuf.h
@@ -56,6 +56,7 @@ struct iobuf_struct {
IOBUF chain, byte *buf, size_t *len);
void *filter_ov; /* value for opaque */
int filter_ov_owner;
+ char *real_fname;
IOBUF chain; /* next iobuf used for i/o if any (passed to filter) */
int no, subno;
const char *desc;
@@ -114,6 +115,7 @@ size_t iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen );
void iobuf_unget_and_close_temp( IOBUF a, IOBUF temp );
u32 iobuf_get_filelength( IOBUF a );
+const char *iobuf_get_real_fname( IOBUF a );
const char *iobuf_get_fname( IOBUF a );
void iobuf_set_block_mode( IOBUF a, size_t n );
diff --git a/mpi/ChangeLog b/mpi/ChangeLog
index db2d7025e..959f3b48c 100644
--- a/mpi/ChangeLog
+++ b/mpi/ChangeLog
@@ -1,3 +1,7 @@
+Tue Jun 1 16:01:46 CEST 1999 Werner Koch <[email protected]>
+
+ * config.links (i[56]86*-*-freebsdelf*): New.
+
Sun May 23 14:20:22 CEST 1999 Werner Koch <[email protected]>
* config.links (sysdep.h): Not any more conditionally created.
diff --git a/mpi/config.links b/mpi/config.links
index 4caf2b8d6..376d42b71 100644
--- a/mpi/config.links
+++ b/mpi/config.links
@@ -12,12 +12,12 @@ echo '/* created by config.links - do not edit */' >./mpi/asm-syntax.h
if test "$try_asm_modules" = "yes" ; then
case "${target}" in
- i[34]86*-*-freebsd*-elf | i[34]86*-*-freebsd[34]*)
+ i[34]86*-*-freebsd*-elf | i[34]86*-*-freebsd[34]* | i[34]86*-*-freebsdelf*)
echo '#define ELF_SYNTAX' >>./mpi/asm-syntax.h
cat $srcdir/mpi/i386/syntax.h >>./mpi/asm-syntax.h
path="i386"
;;
- i[56]86*-*-freebsd*-elf | i[56]86*-*-freebsd[34]*)
+ i[56]86*-*-freebsd*-elf | i[56]86*-*-freebsd[34]* | i[56]86*-*-freebsdelf*)
echo '#define ELF_SYNTAX' >>./mpi/asm-syntax.h
cat $srcdir/mpi/i386/syntax.h >>./mpi/asm-syntax.h
path="i586 i386"
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index cbbe10d25..62cb882d6 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -103,6 +103,12 @@ mpi_alloc_secure( unsigned nlimbs )
}
+#if 0
+static void *unused_limbs_5;
+static void *unused_limbs_32;
+static void *unused_limbs_64;
+#endif
+
mpi_ptr_t
#ifdef M_DEBUG
mpi_debug_alloc_limb_space( unsigned nlimbs, int secure, const char *info )
@@ -111,14 +117,37 @@ mpi_alloc_limb_space( unsigned nlimbs, int secure )
#endif
{
size_t len = nlimbs * sizeof(mpi_limb_t);
+ mpi_ptr_t p;
if( DBG_MEMORY )
log_debug("mpi_alloc_limb_space(%u)\n", (unsigned)len*8 );
+ #if 0
+ if( !secure ) {
+ if( nlimbs == 5 && unused_limbs_5 ) { /* DSA 160 bits */
+ p = unused_limbs_5;
+ unused_limbs_5 = *p;
+ return p;
+ }
+ else if( nlimbs == 32 && unused_limbs_32 ) { /* DSA 1024 bits */
+ p = unused_limbs_32;
+ unused_limbs_32 = *p;
+ return p;
+ }
+ else if( nlimbs == 64 && unused_limbs_64 ) { /* DSA 2*1024 bits */
+ p = unused_limbs_64;
+ unused_limbs_64 = *p;
+ return p;
+ }
+ }
+ #endif
+
#ifdef M_DEBUG
- return secure? m_debug_alloc_secure(len, info):m_debug_alloc( len, info );
+ p = secure? m_debug_alloc_secure(len, info):m_debug_alloc( len, info );
#else
- return secure? m_alloc_secure( len ):m_alloc( len );
+ p = secure? m_alloc_secure( len ):m_alloc( len );
#endif
+
+ return p;
}
void
@@ -132,6 +161,31 @@ mpi_free_limb_space( mpi_ptr_t a )
return;
if( DBG_MEMORY )
log_debug("mpi_free_limb_space of size %lu\n", (ulong)m_size(a)*8 );
+
+ #if 0
+ if( !m_is_secure(a) ) {
+ size_t nlimbs = m_size(a) / 4 ;
+ void *p = a;
+
+ if( nlimbs == 5 ) { /* DSA 160 bits */
+ *a = unused_limbs_5;
+ unused_limbs_5 = a;
+ return;
+ }
+ else if( nlimbs == 32 ) { /* DSA 1024 bits */
+ *a = unused_limbs_32;
+ unused_limbs_32 = a;
+ return;
+ }
+ else if( nlimbs == 64 ) { /* DSA 2*1024 bits */
+ *a = unused_limbs_64;
+ unused_limbs_64 = a;
+ return;
+ }
+ }
+ #endif
+
+
m_free(a);
}
diff --git a/util/ChangeLog b/util/ChangeLog
index e0288e2ef..ad2a85a66 100644
--- a/util/ChangeLog
+++ b/util/ChangeLog
@@ -1,3 +1,8 @@
+Tue Jun 1 16:01:46 CEST 1999 Werner Koch <[email protected]>
+
+ * iobuf.c (iobuf_get_real_fname): Made global and now keep a
+ copy of the name in the iobuf struct.
+
Mon May 31 19:41:10 CEST 1999 Werner Koch <[email protected]>
* iobuf.c (file_filter,block_filter): Speed patches (R�mi).
diff --git a/util/iobuf.c b/util/iobuf.c
index 8e49a1606..e5379d9ce 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -58,7 +58,6 @@ typedef struct {
static int underflow(IOBUF a);
-static const char *get_real_fname( IOBUF a );
/****************
* Read data from a file into buf which has an allocated length of *LEN.
@@ -449,6 +448,7 @@ iobuf_alloc(int use, size_t bufsize)
a->no = ++number;
a->subno = 0;
a->opaque = NULL;
+ a->real_fname = NULL;
return a;
}
@@ -462,6 +462,7 @@ iobuf_close( IOBUF a )
if( a && a->directfp ) {
fclose( a->directfp );
+ m_free( a->real_fname );
if( DBG_IOBUF )
log_debug("iobuf_close -> %p\n", a->directfp );
return 0;
@@ -477,6 +478,7 @@ iobuf_close( IOBUF a )
if( a->filter && (rc = a->filter(a->filter_ov, IOBUFCTRL_FREE,
a->chain, NULL, &dummy_len)) )
log_error("IOBUFCTRL_FREE failed on close: %s\n", g10_errstr(rc) );
+ m_free(a->real_fname);
m_free(a->d.buf);
m_free(a);
}
@@ -489,7 +491,7 @@ iobuf_cancel( IOBUF a )
const char *s;
if( a && a->use == 2 ) {
- s = get_real_fname(a);
+ s = iobuf_get_real_fname(a);
if( s && *s )
remove(s); /* remove the file. Fixme: this will fail for MSDOZE*/
} /* because the file is still open */
@@ -550,6 +552,8 @@ iobuf_open( const char *fname )
fcx->fp = fp;
fcx->print_only_name = print_only;
strcpy(fcx->fname, fname );
+ if( !print_only )
+ a->real_fname = m_strdup( fname );
a->filter = file_filter;
a->filter_ov = fcx;
file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
@@ -614,6 +618,8 @@ iobuf_create( const char *fname )
fcx->fp = fp;
fcx->print_only_name = print_only;
strcpy(fcx->fname, fname );
+ if( !print_only )
+ a->real_fname = m_strdup( fname );
a->filter = file_filter;
a->filter_ov = fcx;
file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
@@ -644,6 +650,7 @@ iobuf_append( const char *fname )
fcx = m_alloc( sizeof *fcx + strlen(fname) );
fcx->fp = fp;
strcpy(fcx->fname, fname );
+ a->real_fname = m_strdup( fname );
a->filter = file_filter;
a->filter_ov = fcx;
file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
@@ -670,6 +677,7 @@ iobuf_openrw( const char *fname )
fcx = m_alloc( sizeof *fcx + strlen(fname) );
fcx->fp = fp;
strcpy(fcx->fname, fname );
+ a->real_fname = m_strdup( fname );
a->filter = file_filter;
a->filter_ov = fcx;
file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
@@ -703,6 +711,7 @@ iobuf_fopen( const char *fname, const char *mode )
return NULL;
a = iobuf_alloc(1, 8192 );
a->directfp = fp;
+ a->real_fname = m_strdup( fname );
if( DBG_IOBUF )
log_debug("iobuf_fopen -> %p\n", a->directfp );
@@ -745,6 +754,10 @@ iobuf_push_filter2( IOBUF a,
*/
b = m_alloc(sizeof *b);
memcpy(b, a, sizeof *b );
+ /* fixme: it is stupid to keep a copy of the name at every level
+ * but we need the name somewhere because the name known by file_filter
+ * may have been released when we need the name of the file */
+ b->real_fname = a->real_fname? m_strdup(a->real_fname):NULL;
/* remove the filter stuff from the new stream */
a->filter = NULL;
a->filter_ov = NULL;
@@ -811,6 +824,7 @@ pop_filter( IOBUF a, int (*f)(void *opaque, int control,
b = a->chain;
assert(b);
m_free(a->d.buf);
+ m_free(a->real_fname);
memcpy(a,b, sizeof *a);
m_free(b);
return 0;
@@ -847,6 +861,7 @@ pop_filter( IOBUF a, int (*f)(void *opaque, int control,
*/
b = a->chain;
m_free(a->d.buf);
+ m_free(a->real_fname);
memcpy(a,b, sizeof *a);
m_free(b);
if( DBG_IOBUF )
@@ -884,6 +899,7 @@ underflow(IOBUF a)
log_debug("iobuf-%d.%d: pop `%s' in underflow\n",
a->no, a->subno, a->desc );
m_free(a->d.buf);
+ m_free(a->real_fname);
memcpy(a, b, sizeof *a);
m_free(b);
print_chain(a);
@@ -952,6 +968,7 @@ underflow(IOBUF a)
a->no, a->subno, a->desc );
print_chain(a);
m_free(a->d.buf);
+ m_free(a->real_fname);
memcpy(a,b, sizeof *a);
m_free(b);
print_chain(a);
@@ -1075,18 +1092,22 @@ iobuf_read(IOBUF a, byte *buf, unsigned buflen )
do {
if( n < buflen && a->d.start < a->d.len ) {
unsigned size = a->d.len - a->d.start;
- if( size > buflen - n ) size = buflen - n;
- if( buf ) memcpy( buf, a->d.buf + a->d.start, size );
+ if( size > buflen - n )
+ size = buflen - n;
+ if( buf )
+ memcpy( buf, a->d.buf + a->d.start, size );
n += size;
a->d.start += size;
- if( buf ) buf += size;
+ if( buf )
+ buf += size;
}
if( n < buflen ) {
if( (c=underflow(a)) == -1 ) {
a->nbytes += n;
return n? n : -1/*EOF*/;
}
- if( buf ) *buf++ = c;
+ if( buf )
+ *buf++ = c;
n++;
}
} while( n < buflen );
@@ -1251,6 +1272,7 @@ iobuf_get_filelength( IOBUF a )
return 0;
}
+ /* Hmmm: file_filter may have already been removed */
for( ; a; a = a->chain )
if( !a->chain && a->filter == file_filter ) {
file_filter_ctx_t *b = a->filter_ov;
@@ -1331,9 +1353,13 @@ iobuf_seek( IOBUF a, ulong newpos )
/****************
* Retrieve the real filename
*/
-static const char *
-get_real_fname( IOBUF a )
+const char *
+iobuf_get_real_fname( IOBUF a )
{
+ if( a->real_fname )
+ return a->real_fname;
+
+ /* the old solution */
for( ; a; a = a->chain )
if( !a->chain && a->filter == file_filter ) {
file_filter_ctx_t *b = a->filter_ov;
diff --git a/util/memory.c b/util/memory.c
index ebf8f8893..40784375d 100644
--- a/util/memory.c
+++ b/util/memory.c
@@ -48,9 +48,10 @@
#define EXTRA_ALIGN 0
#endif
-static void membug( const char *fmt, ... );
#ifdef M_DEBUG
+ static void membug( const char *fmt, ... );
+
#ifndef M_GUARD
#define M_GUARD 1
#endif
@@ -318,7 +319,6 @@ check_allmem( const char *info )
check_mem(e->user_p-4-EXTRA_ALIGN, info);
}
-#endif /* M_DEBUG */
static void
membug( const char *fmt, ... )
@@ -337,6 +337,7 @@ membug( const char *fmt, ... )
abort();
}
+#endif /* M_DEBUG */
void
m_print_stats( const char *prefix )