aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2005-01-06 16:23:47 +0000
committerDavid Shaw <[email protected]>2005-01-06 16:23:47 +0000
commitf464dcef5946501d4c99e4f8f608a59c5e12392f (patch)
treeb46f8d1395ac4fadece08459690ded1195d408b6
parent(set_native_charset): Assume that ASCII, (diff)
downloadgnupg-f464dcef5946501d4c99e4f8f608a59c5e12392f.tar.gz
gnupg-f464dcef5946501d4c99e4f8f608a59c5e12392f.zip
* filter.h, armor.c (armor_filter): Use the eol string from the armor
filter context instead of hardcoding '\n' or '\r\n'. If no eol string is provided, default to '\n' or '\r\n' as appropriate. (is_armor_header): Trim tabs in armor header lines as well. * keyserver.c (keyserver_spawn): Use it here to force '\n' line endings since the keyserver output file gets a LF->CRLF expansion on win32.
-rw-r--r--g10/ChangeLog11
-rw-r--r--g10/armor.c67
-rw-r--r--g10/filter.h7
-rw-r--r--g10/keyserver.c9
4 files changed, 66 insertions, 28 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 8493bdad0..e113d4519 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,14 @@
+2005-01-06 David Shaw <[email protected]>
+
+ * filter.h, armor.c (armor_filter): Use the eol string from the
+ armor filter context instead of hardcoding '\n' or '\r\n'. If no
+ eol string is provided, default to '\n' or '\r\n' as appropriate.
+ (is_armor_header): Trim tabs in armor header lines as well.
+
+ * keyserver.c (keyserver_spawn): Use it here to force '\n' line
+ endings since the keyserver output file gets a LF->CRLF expansion
+ on win32.
+
2005-01-05 David Shaw <[email protected]>
* g10.c (main): Typo.
diff --git a/g10/armor.c b/g10/armor.c
index ca63f45f6..55698da91 100644
--- a/g10/armor.c
+++ b/g10/armor.c
@@ -1,6 +1,6 @@
/* armor.c - Armor flter
- * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
- * 2004 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+ * 2005 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -38,12 +38,6 @@
#include "status.h"
#include "i18n.h"
-#ifdef HAVE_DOSISH_SYSTEM
-#define LF "\r\n"
-#else
-#define LF "\n"
-#endif
-
#define MAX_LINELEN 20000
#define CRCINIT 0xB704CE
@@ -119,7 +113,6 @@ static char *tail_strings[] = {
};
-
static void
initialize(void)
{
@@ -306,7 +299,7 @@ is_armor_header( byte *line, unsigned len )
p++;
}
else
- while(*p==' ' || *p=='\r' || *p=='\n')
+ while(*p==' ' || *p=='\r' || *p=='\n' || *p=='\t')
p++;
if( *p )
@@ -984,10 +977,14 @@ armor_filter( void *opaque, int control,
log_bug("afx->what=%d", afx->what);
iobuf_writestr(a, "-----");
iobuf_writestr(a, head_strings[afx->what] );
- iobuf_writestr(a, "-----" LF );
+ iobuf_writestr(a, "-----" );
+ iobuf_writestr(a,afx->eol);
if( !opt.no_version )
+ {
iobuf_writestr(a, "Version: GnuPG v" VERSION " ("
- PRINTABLE_OS_NAME ")" LF );
+ PRINTABLE_OS_NAME ")" );
+ iobuf_writestr(a,afx->eol);
+ }
/* write the comment strings */
for(s=comment->d;comment;comment=comment->next,s=comment->d)
@@ -1004,7 +1001,8 @@ armor_filter( void *opaque, int control,
else
iobuf_put(a, *s );
}
- iobuf_writestr(a, LF );
+
+ iobuf_writestr(a,afx->eol);
}
if ( afx->hdrlines ) {
@@ -1016,7 +1014,8 @@ armor_filter( void *opaque, int control,
iobuf_put(a, *s );
}
}
- iobuf_writestr(a, LF );
+
+ iobuf_writestr(a,afx->eol);
afx->status++;
afx->idx = 0;
afx->idx2 = 0;
@@ -1045,10 +1044,11 @@ armor_filter( void *opaque, int control,
iobuf_put(a, c);
c = bintoasc[radbuf[2]&077];
iobuf_put(a, c);
- if( ++idx2 >= (64/4) ) { /* pgp doesn't like 72 here */
- iobuf_writestr(a, LF );
+ if( ++idx2 >= (64/4) )
+ { /* pgp doesn't like 72 here */
+ iobuf_writestr(a,afx->eol);
idx2=0;
- }
+ }
}
}
for(i=0; i < idx; i++ )
@@ -1057,10 +1057,23 @@ armor_filter( void *opaque, int control,
afx->idx2 = idx2;
afx->crc = crc;
}
- else if( control == IOBUFCTRL_INIT ) {
+ else if( control == IOBUFCTRL_INIT )
+ {
if( !is_initialized )
- initialize();
- }
+ initialize();
+
+ /* Figure out what we're using for line endings if the caller
+ didn't specify. */
+ if(afx->eol[0]==0)
+ {
+#ifdef HAVE_DOSISH_SYSTEM
+ afx->eol[0]='\r';
+ afx->eol[1]='\n';
+#else
+ afx->eol[0]='\n';
+#endif
+ }
+ }
else if( control == IOBUFCTRL_CANCEL ) {
afx->cancel = 1;
}
@@ -1089,14 +1102,15 @@ armor_filter( void *opaque, int control,
iobuf_put(a, c);
iobuf_put(a, '=');
}
- if( ++idx2 >= (64/4) ) { /* pgp doesn't like 72 here */
- iobuf_writestr(a, LF );
+ if( ++idx2 >= (64/4) )
+ { /* pgp doesn't like 72 here */
+ iobuf_writestr(a,afx->eol);
idx2=0;
- }
+ }
}
/* may need a linefeed */
if( idx2 )
- iobuf_writestr(a, LF );
+ iobuf_writestr(a,afx->eol);
/* write the CRC */
iobuf_put(a, '=');
radbuf[0] = crc >>16;
@@ -1110,13 +1124,14 @@ armor_filter( void *opaque, int control,
iobuf_put(a, c);
c = bintoasc[radbuf[2]&077];
iobuf_put(a, c);
- iobuf_writestr(a, LF );
+ iobuf_writestr(a,afx->eol);
/* and the the trailer */
if( afx->what >= DIM(tail_strings) )
log_bug("afx->what=%d", afx->what);
iobuf_writestr(a, "-----");
iobuf_writestr(a, tail_strings[afx->what] );
- iobuf_writestr(a, "-----" LF );
+ iobuf_writestr(a, "-----" );
+ iobuf_writestr(a,afx->eol);
}
else if( !afx->any_data && !afx->inp_bypass ) {
log_error(_("no valid OpenPGP data found.\n"));
diff --git a/g10/filter.h b/g10/filter.h
index fed70c25c..b8e3edac6 100644
--- a/g10/filter.h
+++ b/g10/filter.h
@@ -1,5 +1,6 @@
/* filter.h
- * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2003,
+ * 2005 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -48,6 +49,10 @@ typedef struct {
int truncated; /* number of truncated lines */
int qp_detected;
int pgp2mode;
+ byte eol[3]; /* The end of line characters as a
+ zero-terminated string. Defaults
+ (eol[0]=='\0') to whatever the local
+ platform uses. */
byte *buffer; /* malloced buffer */
unsigned buffer_size; /* and size of this buffer */
diff --git a/g10/keyserver.c b/g10/keyserver.c
index f9343980a..735b7ebe1 100644
--- a/g10/keyserver.c
+++ b/g10/keyserver.c
@@ -1,5 +1,5 @@
/* keyserver.c - generic keyserver code
- * Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -966,6 +966,13 @@ keyserver_spawn(int action,STRLIST list,KEYDB_SEARCH_DESC *desc,
memset(&afx,0,sizeof(afx));
afx.what=1;
+ /* Tell the armor filter to use Unix-style \n line
+ endings, since we're going to fprintf this to a file
+ that (on Win32) is open in text mode. The win32 stdio
+ will transform the \n to \r\n and we'll end up with the
+ proper line endings on win32. This is a no-op on
+ Unix. */
+ afx.eol[0]='\n';
iobuf_push_filter(buffer,armor_filter,&afx);
/* TODO: Remove Comment: lines from keys exported this