mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-01 16:33:02 +01:00
gpg: Simplify an interactive import status line.
* g10/cpr.c (write_status_printf): Escape CR and LF. * g10/import.c (print_import_check): Simplify by using write_status_printf and hexfingerprint. Signed-off-by: Werner Koch <wk@gnupg.org> Fixed one conlict in a comment.
This commit is contained in:
parent
ee08a15e31
commit
184fbf014a
34
g10/cpr.c
34
g10/cpr.c
@ -142,7 +142,8 @@ write_status ( int no )
|
|||||||
|
|
||||||
|
|
||||||
/* Write a status line with code NO followed by the string TEXT and
|
/* Write a status line with code NO followed by the string TEXT and
|
||||||
directly followed by the remaining strings up to a NULL. */
|
* directly followed by the remaining strings up to a NULL. Embedded
|
||||||
|
* CR and LFs in the strings (but not in TEXT) are C-style escaped.*/
|
||||||
void
|
void
|
||||||
write_status_strings (int no, const char *text, ...)
|
write_status_strings (int no, const char *text, ...)
|
||||||
{
|
{
|
||||||
@ -187,13 +188,13 @@ write_status_text (int no, const char *text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Write a status line with code NO followed by the outout of the
|
/* Write a status line with code NO followed by the output of the
|
||||||
* printf style FORMAT. The caller needs to make sure that LFs and
|
* printf style FORMAT. Embedded CR and LFs are C-style escaped. */
|
||||||
* CRs are not printed. */
|
|
||||||
void
|
void
|
||||||
write_status_printf (int no, const char *format, ...)
|
write_status_printf (int no, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list arg_ptr;
|
va_list arg_ptr;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
if (!statusfp || !status_currently_allowed (no) )
|
if (!statusfp || !status_currently_allowed (no) )
|
||||||
return; /* Not enabled or allowed. */
|
return; /* Not enabled or allowed. */
|
||||||
@ -204,7 +205,30 @@ write_status_printf (int no, const char *format, ...)
|
|||||||
{
|
{
|
||||||
es_putc ( ' ', statusfp);
|
es_putc ( ' ', statusfp);
|
||||||
va_start (arg_ptr, format);
|
va_start (arg_ptr, format);
|
||||||
es_vfprintf (statusfp, format, arg_ptr);
|
buf = gpgrt_vbsprintf (format, arg_ptr);
|
||||||
|
if (!buf)
|
||||||
|
log_error ("error printing status line: %s\n",
|
||||||
|
gpg_strerror (gpg_err_code_from_syserror ()));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (strpbrk (buf, "\r\n"))
|
||||||
|
{
|
||||||
|
const byte *s;
|
||||||
|
for (s=buf; *s; s++)
|
||||||
|
{
|
||||||
|
if (*s == '\n')
|
||||||
|
es_fputs ("\\n", statusfp);
|
||||||
|
else if (*s == '\r')
|
||||||
|
es_fputs ("\\r", statusfp);
|
||||||
|
else
|
||||||
|
es_fputc (*s, statusfp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
es_fputs (buf, statusfp);
|
||||||
|
gpgrt_free (buf);
|
||||||
|
}
|
||||||
|
|
||||||
va_end (arg_ptr);
|
va_end (arg_ptr);
|
||||||
}
|
}
|
||||||
es_putc ('\n', statusfp);
|
es_putc ('\n', statusfp);
|
||||||
|
19
g10/import.c
19
g10/import.c
@ -1080,23 +1080,14 @@ print_import_ok (PKT_public_key *pk, unsigned int reason)
|
|||||||
static void
|
static void
|
||||||
print_import_check (PKT_public_key * pk, PKT_user_id * id)
|
print_import_check (PKT_public_key * pk, PKT_user_id * id)
|
||||||
{
|
{
|
||||||
char * buf;
|
byte hexfpr[2*MAX_FINGERPRINT_LEN+1];
|
||||||
byte fpr[24];
|
|
||||||
u32 keyid[2];
|
u32 keyid[2];
|
||||||
size_t i, n;
|
|
||||||
size_t pos = 0;
|
|
||||||
|
|
||||||
buf = xmalloc (17+41+id->len+32);
|
|
||||||
keyid_from_pk (pk, keyid);
|
keyid_from_pk (pk, keyid);
|
||||||
sprintf (buf, "%08X%08X ", keyid[0], keyid[1]);
|
hexfingerprint (pk, hexfpr, sizeof hexfpr);
|
||||||
pos = 17;
|
write_status_printf (STATUS_IMPORT_CHECK, "%08X%08X %s %s",
|
||||||
fingerprint_from_pk (pk, fpr, &n);
|
keyid[0], keyid[1], hexfpr, id->name);
|
||||||
for (i = 0; i < n; i++, pos += 2)
|
|
||||||
sprintf (buf+pos, "%02X", fpr[i]);
|
|
||||||
strcat (buf, " ");
|
|
||||||
strcat (buf, id->name);
|
|
||||||
write_status_text (STATUS_IMPORT_CHECK, buf);
|
|
||||||
xfree (buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user