diff options
Diffstat (limited to 'g10')
-rw-r--r-- | g10/ChangeLog | 8 | ||||
-rw-r--r-- | g10/armor.c | 30 | ||||
-rw-r--r-- | g10/filter.h | 9 | ||||
-rw-r--r-- | g10/free-packet.c | 5 | ||||
-rw-r--r-- | g10/sign.c | 2 | ||||
-rw-r--r-- | g10/textfilter.c | 117 |
6 files changed, 57 insertions, 114 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog index 60259ce4d..f5a694a8b 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,11 @@ +Sun Jan 17 11:04:33 CET 1999 Werner Koch <[email protected]> + + * textfilter.c (text_filter): Now uses iobuf_read_line(). + (read_line): Removed. + + * armor.c (trim_trailing_spaces): Removed and replaced + by trim_trailing_ws from libutil + Sat Jan 16 12:03:27 CET 1999 Werner Koch <[email protected]> * hkp.c (hkp_ask_import): Use only the short keyid diff --git a/g10/armor.c b/g10/armor.c index 1f23c6f64..491cab4fa 100644 --- a/g10/armor.c +++ b/g10/armor.c @@ -256,31 +256,6 @@ parse_hash_header( const char *line ) - -static unsigned -trim_trailing_spaces( byte *line, unsigned len ) -{ - byte *p, *mark; - unsigned n; - - for(mark=NULL, p=line, n=0; n < len; n++, p++ ) { - if( strchr(" \t\r\n", *p ) ) { - if( !mark ) - mark = p; - } - else - mark = NULL; - } - - if( mark ) { - *mark = 0; - return mark - line; - } - return len; -} - - - /**************** * Check whether this is a armor line. * returns: -1 if it is not a armor header or the index number of the @@ -339,7 +314,7 @@ parse_header_line( armor_filter_context_t *afx, byte *line, unsigned len ) if( *line == '\n' || ( len && (*line == '\r' && line[1]=='\n') ) ) return 0; /* empty line */ - len = trim_trailing_spaces( line, len ); + len = trim_trailing_ws( line, len ); p = strchr( line, ':'); if( !p || !p[1] ) { log_error(_("invalid armor header: ")); @@ -521,8 +496,7 @@ fake_packet( armor_filter_context_t *afx, IOBUF a, if( !maxlen ) afx->truncated++; if( !afx->not_dash_escaped ) - afx->buffer_len = trim_trailing_spaces( afx->buffer, - afx->buffer_len ); + afx->buffer_len = trim_trailing_ws( afx->buffer, afx->buffer_len ); p = afx->buffer; n = afx->buffer_len; diff --git a/g10/filter.h b/g10/filter.h index f0448f1bd..ebd58e370 100644 --- a/g10/filter.h +++ b/g10/filter.h @@ -80,10 +80,11 @@ typedef struct { typedef struct { - int eof; - size_t idx; - size_t len; - byte buf[256]; + byte *buffer; /* malloced buffer */ + unsigned buffer_size; /* and size of this buffer */ + unsigned buffer_len; /* used length of the buffer */ + unsigned buffer_pos; /* read position */ + int truncated; /* number of truncated lines */ } text_filter_context_t; diff --git a/g10/free-packet.c b/g10/free-packet.c index e953b0d45..78f81bd0a 100644 --- a/g10/free-packet.c +++ b/g10/free-packet.c @@ -444,6 +444,11 @@ cmp_signatures( PKT_signature *a, PKT_signature *b ) return 0; } + + +/**************** + * Returns: true if the user ids do not match + */ int cmp_user_ids( PKT_user_id *a, PKT_user_id *b ) { diff --git a/g10/sign.c b/g10/sign.c index b011043b2..e8582f43d 100644 --- a/g10/sign.c +++ b/g10/sign.c @@ -349,8 +349,6 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr, * data, it is not possible to know the used length * without a double read of the file - to avoid that * we simple use partial length packets. - * FIXME: We have to do the double read when opt.rfc1991 - * is active. */ if( opt.textmode && !outfile ) filesize = 0; diff --git a/g10/textfilter.c b/g10/textfilter.c index 9e820d159..9959c9335 100644 --- a/g10/textfilter.c +++ b/g10/textfilter.c @@ -30,72 +30,10 @@ #include "memory.h" #include "util.h" #include "filter.h" +#include "i18n.h" - - -static int -read_line( byte *buf, size_t *r_buflen, IOBUF a ) -{ - int c; - int rc = 0; - byte *p; - size_t buflen; - int no_lf=0; - size_t n; - - buflen = *r_buflen; - assert(buflen >= 20 ); - buflen -= 3; /* leave some room for CR,LF and one extra */ - - for(c=0, n=0; n < buflen && (c=iobuf_get(a)) != -1 && c != '\n'; ) - buf[n++] = c; - buf[n] = 0; - if( c == -1 ) { - rc = -1; - if( !n || buf[n-1] != '\n' ) - no_lf = 1; - } - else if( c != '\n' ) { - IOBUF b = iobuf_temp(); - while( (c=iobuf_get(a)) != -1 && c != '\n' ) { - iobuf_put(b,c); - if( c != ' ' && c != '\t' && c != '\r' ) - break; - } - if( c == '\n' ) { /* okay we can skip the rest of the line */ - iobuf_close(b); - } - else { - iobuf_unget_and_close_temp(a,b); - no_lf = 1; - } - } - - if( !no_lf ) { - /* append CR,LF after removing trailing wspaces */ - for(p=buf+n-1; n; n--, p-- ) { - assert( *p != '\n' ); - if( *p != ' ' && *p != '\t' && *p != '\r' ) { - p[1] = '\r'; - p[2] = '\n'; - n += 2; - break; - } - } - if( !n ) { - buf[0] = '\r'; - buf[1] = '\n'; - n = 2; - } - } - - - *r_buflen = n; - return rc; -} - - +#define MAX_LINELEN 20000 /**************** @@ -109,33 +47,52 @@ text_filter( void *opaque, int control, size_t size = *ret_len; text_filter_context_t *tfx = opaque; int rc=0; - size_t len, n, nn; if( control == IOBUFCTRL_UNDERFLOW ) { - assert( size > 30 ); - len = 0; + size_t len = 0; + unsigned maxlen; + + assert( size > 10 ); + size -= 2; /* reserve 2 bytes to append CR,LF */ while( !rc && len < size ) { - if( tfx->idx < tfx->len ) { /* flush the last buffer */ - n = tfx->len; - for(nn=tfx->idx; len < size && nn < n ; nn++ ) - buf[len++] = tfx->buf[nn]; - tfx->idx = nn; + int lf_seen; + + while( len < size && tfx->buffer_pos < tfx->buffer_len ) + buf[len++] = tfx->buffer[tfx->buffer_pos++]; + if( len >= size ) continue; + + /* read the next line */ + maxlen = MAX_LINELEN; + tfx->buffer_pos = 0; + tfx->buffer_len = iobuf_read_line( a, &tfx->buffer, + &tfx->buffer_size, &maxlen ); + if( !maxlen ) + tfx->truncated++; + if( !tfx->buffer_len ) { + if( !len ) + rc = -1; /* eof */ + break; } - if( tfx->eof ) { - rc = -1; - continue; + lf_seen = tfx->buffer[tfx->buffer_len-1] == '\n'; + tfx->buffer_len = trim_trailing_ws( tfx->buffer, tfx->buffer_len ); + if( lf_seen ) { + tfx->buffer[tfx->buffer_len++] = '\r'; + tfx->buffer[tfx->buffer_len++] = '\n'; } - n = DIM(tfx->buf); - tfx->idx = 0; - if( read_line( tfx->buf, &n, a ) == -1 ) - tfx->eof = 1; - tfx->len = n; } + *ret_len = len; } else if( control == IOBUFCTRL_DESC ) *(char**)buf = "text_filter"; + else if( control == IOBUFCTRL_FREE ) { + if( tfx->truncated ) + log_error(_("can't handle text lines longer than %d characters\n"), + MAX_LINELEN ); + m_free( tfx->buffer ); + tfx->buffer = NULL; + } return rc; } |