mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
fixed clearsig stuff
This commit is contained in:
parent
ccb3140ab2
commit
5aed77d1db
28 changed files with 1428 additions and 584 deletions
|
@ -33,6 +33,46 @@
|
|||
#include "i18n.h"
|
||||
|
||||
|
||||
/****************
|
||||
* Defer the last CR,LF
|
||||
*/
|
||||
static void
|
||||
special_md_putc( MD_HANDLE md, int c, int *state )
|
||||
{
|
||||
if( c == -1 ) { /* flush */
|
||||
if( *state == 1 ) {
|
||||
md_putc(md, '\r');
|
||||
}
|
||||
*state = 0;
|
||||
return;
|
||||
}
|
||||
again:
|
||||
switch( *state ) {
|
||||
case 0:
|
||||
if( c == '\r' )
|
||||
*state = 1;
|
||||
else
|
||||
md_putc(md, c );
|
||||
break;
|
||||
case 1:
|
||||
if( c == '\n' )
|
||||
*state = 2;
|
||||
else {
|
||||
md_putc(md, '\r');
|
||||
*state = 0;
|
||||
goto again;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
md_putc(md, '\r');
|
||||
md_putc(md, '\n');
|
||||
*state = 0;
|
||||
goto again;
|
||||
default: BUG();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
* Handle a plaintext packet. If MFX is not NULL, update the MDs
|
||||
* Note: we should use the filter stuff here, but we have to add some
|
||||
|
@ -40,13 +80,15 @@
|
|||
* bytes from the plaintext.
|
||||
*/
|
||||
int
|
||||
handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, int nooutput )
|
||||
handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
|
||||
int nooutput, int clearsig )
|
||||
{
|
||||
char *fname = NULL;
|
||||
FILE *fp = NULL;
|
||||
int rc = 0;
|
||||
int c;
|
||||
int convert = pt->mode == 't';
|
||||
int special_state = 0;
|
||||
|
||||
/* create the filename as C string */
|
||||
if( nooutput )
|
||||
|
@ -86,10 +128,14 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, int nooutput )
|
|||
rc = G10ERR_READ_FILE;
|
||||
goto leave;
|
||||
}
|
||||
if( mfx->md )
|
||||
md_putc(mfx->md, c );
|
||||
if( mfx->md ) {
|
||||
if( convert && clearsig )
|
||||
special_md_putc(mfx->md, c, &special_state );
|
||||
else
|
||||
md_putc(mfx->md, c );
|
||||
}
|
||||
if( convert && c == '\r' )
|
||||
continue; /* FIXME: this hack is too simple */
|
||||
continue; /* fixme: this hack might be too simple */
|
||||
if( fp ) {
|
||||
if( putc( c, fp ) == EOF ) {
|
||||
log_error("Error writing to '%s': %s\n",
|
||||
|
@ -102,10 +148,14 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, int nooutput )
|
|||
}
|
||||
else {
|
||||
while( (c = iobuf_get(pt->buf)) != -1 ) {
|
||||
if( mfx->md )
|
||||
md_putc(mfx->md, c );
|
||||
if( mfx->md ) {
|
||||
if( convert && clearsig )
|
||||
special_md_putc(mfx->md, c, &special_state );
|
||||
else
|
||||
md_putc(mfx->md, c );
|
||||
}
|
||||
if( convert && c == '\r' )
|
||||
continue; /* FIXME: this hack is too simple */
|
||||
continue; /* fixme: this hack might be too simple */
|
||||
if( fp ) {
|
||||
if( putc( c, fp ) == EOF ) {
|
||||
log_error("Error writing to '%s': %s\n",
|
||||
|
@ -117,6 +167,8 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, int nooutput )
|
|||
}
|
||||
iobuf_clear_eof(pt->buf);
|
||||
}
|
||||
if( mfx->md && convert && clearsig )
|
||||
special_md_putc(mfx->md, -1, &special_state ); /* flush */
|
||||
|
||||
if( fp && fp != stdout && fclose(fp) ) {
|
||||
log_error("Error closing '%s': %s\n", fname, strerror(errno) );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue