summaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1999-05-31 19:49:37 +0200
committerWerner Koch <wk@gnupg.org>1999-05-31 19:49:37 +0200
commitc34c67695888aafe5fb4fa0b2c2345bede16cefe (patch)
treed0a9d9d99d05a6a530712a4a432ecaf6ea94c880 /g10
parentSee ChangeLog: Thu May 27 09:40:55 CEST 1999 Werner Koch (diff)
downloadgnupg2-c34c67695888aafe5fb4fa0b2c2345bede16cefe.tar.xz
gnupg2-c34c67695888aafe5fb4fa0b2c2345bede16cefe.zip
See ChangeLog: Mon May 31 19:41:10 CEST 1999 Werner Koch
Diffstat (limited to 'g10')
-rw-r--r--g10/ChangeLog7
-rw-r--r--g10/build-packet.c2
-rw-r--r--g10/compress.c24
-rw-r--r--g10/encr-data.c9
-rw-r--r--g10/free-packet.c14
-rw-r--r--g10/g10.c5
-rw-r--r--g10/mdfilter.c10
-rw-r--r--g10/plaintext.c103
8 files changed, 113 insertions, 61 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 6c1fe9f50..5096b94fa 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,10 @@
+Mon May 31 19:41:10 CEST 1999 Werner Koch <wk@isil.d.shuttle.de>
+
+ * g10.c (main): Fix for SHM init (Michael).
+
+ * compress.c, encr-data.c, mdfilter.c,
+ plaintext.c, free-packet.c: Speed patches (Rémi).
+
Thu May 27 09:40:55 CEST 1999 Werner Koch <wk@isil.d.shuttle.de>
* status.c (cpr_get_answer_yes_no_quit): New.
diff --git a/g10/build-packet.c b/g10/build-packet.c
index ee19287b1..75066de2b 100644
--- a/g10/build-packet.c
+++ b/g10/build-packet.c
@@ -566,7 +566,6 @@ find_subpkt( byte *buffer, sigsubpkttype_t reqtype,
return NULL;
buflen = (*buffer << 8) | buffer[1];
buffer += 2;
- log_debug("find_subpkt: tyoe=%d bufferlength=%d\n", reqtype, buflen );
for(;;) {
if( !buflen )
return NULL; /* end of packets; not found */
@@ -587,7 +586,6 @@ find_subpkt( byte *buffer, sigsubpkttype_t reqtype,
buffer++;
buflen--;
}
- log_debug("find_subpkt: this len=%u\n", n );
if( buflen < n )
break;
type = *buffer & 0x7f;
diff --git a/g10/compress.c b/g10/compress.c
index 5ad4a27de..4862346ad 100644
--- a/g10/compress.c
+++ b/g10/compress.c
@@ -132,8 +132,7 @@ do_uncompress( compress_filter_context_t *zfx, z_stream *zs,
int zrc;
int rc=0;
size_t n;
- byte *p;
- int c;
+ int nread, count;
int refill = !zs->avail_in;
if( DBG_FILTER )
@@ -145,16 +144,17 @@ do_uncompress( compress_filter_context_t *zfx, z_stream *zs,
n = zs->avail_in;
if( !n )
zs->next_in = zfx->inbuf;
- for( p=zfx->inbuf+n; n < zfx->inbufsize; n++, p++ ) {
- if( (c=iobuf_get(a)) == -1 ) {
- /* If we use the undocumented feature to suppress
- * the zlib header, we have to give inflate an
- * extra dummy byte to read */
- if( zfx->algo != 1 || zfx->algo1hack )
- break;
- zfx->algo1hack = 1;
- }
- *p = c & 0xff;
+ count = zfx->inbufsize - n;
+ nread = iobuf_read( a, zfx->inbuf + n, count );
+ if( nread == -1 ) nread = 0;
+ n += nread;
+ /* If we use the undocumented feature to suppress
+ * the zlib header, we have to give inflate an
+ * extra dummy byte to read */
+ if( nread < count && zfx->algo == 1 ) {
+ *(zfx->inbuf + n) = 0xFF; /* is it really needed ? */
+ zfx->algo1hack = 1;
+ n++;
}
zs->avail_in = n;
}
diff --git a/g10/encr-data.c b/g10/encr-data.c
index fd3da055b..0593efe97 100644
--- a/g10/encr-data.c
+++ b/g10/encr-data.c
@@ -217,16 +217,11 @@ decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len)
decode_filter_ctx_t *fc = opaque;
size_t n, size = *ret_len;
int rc = 0;
- int c;
if( control == IOBUFCTRL_UNDERFLOW ) {
assert(a);
- for(n=0; n < size; n++ ) {
- if( (c = iobuf_get(a)) == -1 )
- break;
- buf[n] = c;
- }
-
+ n = iobuf_read( a, buf, size );
+ if( n == -1 ) n = 0;
if( n )
cipher_decrypt( fc->cipher_hd, buf, buf, n);
else
diff --git a/g10/free-packet.c b/g10/free-packet.c
index aef8e2fb0..5d74544fc 100644
--- a/g10/free-packet.c
+++ b/g10/free-packet.c
@@ -229,7 +229,7 @@ free_compressed( PKT_compressed *zd )
if( zd->buf ) { /* have to skip some bytes */
/* don't have any information about the length, so
* we assume this is the last packet */
- while( iobuf_get(zd->buf) != -1 )
+ while( iobuf_read( zd->buf, NULL, 1<<30 ) != -1 )
;
}
m_free(zd);
@@ -240,12 +240,12 @@ free_encrypted( PKT_encrypted *ed )
{
if( ed->buf ) { /* have to skip some bytes */
if( iobuf_in_block_mode(ed->buf) ) {
- while( iobuf_get(ed->buf) != -1 )
+ while( iobuf_read( ed->buf, NULL, 1<<30 ) != -1 )
;
}
else {
- for( ; ed->len; ed->len-- ) /* skip the packet */
- iobuf_get(ed->buf);
+ while( ed->len ) /* skip the packet */
+ ed->len -= iobuf_read( ed->buf, NULL, ed->len );
}
}
m_free(ed);
@@ -257,12 +257,12 @@ free_plaintext( PKT_plaintext *pt )
{
if( pt->buf ) { /* have to skip some bytes */
if( iobuf_in_block_mode(pt->buf) ) {
- while( iobuf_get(pt->buf) != -1 )
+ while( iobuf_read( pt->buf, NULL, 1<<30 ) != -1 )
;
}
else {
- for( ; pt->len; pt->len-- ) /* skip the packet */
- iobuf_get(pt->buf);
+ while( pt->len ) /* skip the packet */
+ pt->len -= iobuf_read( pt->buf, NULL, pt->len );
}
}
m_free(pt);
diff --git a/g10/g10.c b/g10/g10.c
index c53053746..eb6d32ff3 100644
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -554,6 +554,11 @@ main( int argc, char **argv )
opt.shm_coprocess = 1;
requested_shm_size = pargs.r.ret_ulong;
}
+ else if ( pargs.r_opt == oStatusFD ) {
+ /* this is needed to ensure that the status-fd filedescriptor is
+ * initialized when init_shm_coprocessing() is called */
+ set_status_fd( pargs.r.ret_int );
+ }
#endif
}
diff --git a/g10/mdfilter.c b/g10/mdfilter.c
index 2cdbd326d..951fd730e 100644
--- a/g10/mdfilter.c
+++ b/g10/mdfilter.c
@@ -42,17 +42,13 @@ md_filter( void *opaque, int control,
{
size_t size = *ret_len;
md_filter_context_t *mfx = opaque;
- int i, c, rc=0;
+ int i, rc=0;
if( control == IOBUFCTRL_UNDERFLOW ) {
if( mfx->maxbuf_size && size > mfx->maxbuf_size )
size = mfx->maxbuf_size;
- for(i=0; i < size; i++ ) {
- if( (c = iobuf_get(a)) == -1 )
- break;
- buf[i] = c;
- }
-
+ i = iobuf_read( a, buf, size );
+ if( i == -1 ) i = 0;
if( i ) {
md_write(mfx->md, buf, i );
if( mfx->md2 )
diff --git a/g10/plaintext.c b/g10/plaintext.c
index 577641a6d..000ede0c3 100644
--- a/g10/plaintext.c
+++ b/g10/plaintext.c
@@ -90,41 +90,92 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
if( pt->len ) {
assert( !clearsig );
- for( ; pt->len; pt->len-- ) {
- if( (c = iobuf_get(pt->buf)) == -1 ) {
- log_error("Problem reading source (%u bytes remaining)\n",
- (unsigned)pt->len);
- rc = G10ERR_READ_FILE;
- goto leave;
+ 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",
+ (unsigned)pt->len);
+ rc = G10ERR_READ_FILE;
+ goto leave;
+ }
+ if( mfx->md )
+ md_putc(mfx->md, c );
+ if( c == '\r' )
+ continue; /* fixme: this hack might be too simple */
+ if( fp ) {
+ if( putc( c, fp ) == EOF ) {
+ log_error("Error writing to `%s': %s\n",
+ fname, strerror(errno) );
+ rc = G10ERR_WRITE_FILE;
+ goto leave;
+ }
+ }
}
- if( mfx->md )
- md_putc(mfx->md, c );
- if( convert && c == '\r' )
- continue; /* fixme: this hack might be too simple */
- if( fp ) {
- if( putc( c, fp ) == EOF ) {
- log_error("Error writing to `%s': %s\n",
- fname, strerror(errno) );
- rc = G10ERR_WRITE_FILE;
+ }
+ else { // binary mode
+ byte *buffer = m_alloc( 32768 );
+ while( pt->len ) {
+ int len = pt->len > 32768 ? 32768 : pt->len;
+ len = iobuf_read( pt->buf, buffer, len );
+ if( len == -1 ) {
+ log_error("Problem reading source (%u bytes remaining)\n",
+ (unsigned)pt->len);
+ rc = G10ERR_READ_FILE;
+ m_free( buffer );
goto leave;
}
+ if( mfx->md )
+ md_write( mfx->md, buffer, len );
+ if( fp ) {
+ if( fwrite( buffer, 1, len, fp ) != len ) {
+ log_error("Error writing to `%s': %s\n",
+ fname, strerror(errno) );
+ rc = G10ERR_WRITE_FILE;
+ m_free( buffer );
+ goto leave;
+ }
+ }
+ pt->len -= len;
}
+ m_free( buffer );
}
}
else if( !clearsig ) {
- while( (c = iobuf_get(pt->buf)) != -1 ) {
- if( mfx->md )
- md_putc(mfx->md, c );
- if( convert && c == '\r' )
- continue; /* fixme: this hack might be too simple */
- if( fp ) {
- if( putc( c, fp ) == EOF ) {
- log_error("Error writing to `%s': %s\n",
- fname, strerror(errno) );
- rc = G10ERR_WRITE_FILE;
- goto leave;
+ if( convert ) { // text mode
+ while( (c = iobuf_get(pt->buf)) != -1 ) {
+ if( mfx->md )
+ md_putc(mfx->md, c );
+ if( convert && c == '\r' )
+ continue; /* fixme: this hack might be too simple */
+ if( fp ) {
+ if( putc( c, fp ) == EOF ) {
+ log_error("Error writing to `%s': %s\n",
+ fname, strerror(errno) );
+ rc = G10ERR_WRITE_FILE;
+ goto leave;
+ }
+ }
+ }
+ }
+ else { // binary mode
+ byte *buffer = m_alloc( 32768 );
+ for( ;; ) {
+ int len = iobuf_read( pt->buf, buffer, 32768 );
+ if( len == -1 )
+ break;
+ if( mfx->md )
+ md_write( mfx->md, buffer, len );
+ if( fp ) {
+ if( fwrite( buffer, 1, len, fp ) != len ) {
+ log_error("Error writing to `%s': %s\n",
+ fname, strerror(errno) );
+ rc = G10ERR_WRITE_FILE;
+ m_free( buffer );
+ goto leave;
+ }
}
}
+ m_free( buffer );
}
pt->buf = NULL;
}