aboutsummaryrefslogtreecommitdiffstats
path: root/assuan/assuan-util.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <[email protected]>2003-02-01 18:53:06 +0000
committerMarcus Brinkmann <[email protected]>2003-02-01 18:53:06 +0000
commit90beb50551e3fe8be777115cb6ea88b8f54b76b1 (patch)
tree4fcf705e9b3a2d67932bd201beebd22f4cf46425 /assuan/assuan-util.c
parent2003-01-30 Marcus Brinkmann <[email protected]> (diff)
downloadgpgme-90beb50551e3fe8be777115cb6ea88b8f54b76b1.tar.gz
gpgme-90beb50551e3fe8be777115cb6ea88b8f54b76b1.zip
2003-02-01 Marcus Brinkmann <[email protected]>
* assuan/: Update files to 2002-11-10 version of assuan. gpgme/ 2003-02-01 Marcus Brinkmann <[email protected]> * engine-gpgsm.c (map_assuan_error): Replace ASSUAN_Bad_Certificate_Path with ASSUAN_Bad_Certificate_Chain. (gpgsm_new): Use assuan_pipe_connect instead assuan_pipe_connect2. * util.h (DIMof): Remove macro. * ops.h (_gpgme_op_event_cb, _gpgme_op_event_cb_user, _gpgme_data_unread): Prototypes removed.
Diffstat (limited to '')
-rw-r--r--assuan/assuan-util.c124
1 files changed, 79 insertions, 45 deletions
diff --git a/assuan/assuan-util.c b/assuan/assuan-util.c
index 4153ef8d..76f7f065 100644
--- a/assuan/assuan-util.c
+++ b/assuan/assuan-util.c
@@ -1,27 +1,28 @@
/* assuan-util.c - Utility functions for Assuan
- * Copyright (C) 2001 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
*
- * This file is part of GnuPG.
+ * This file is part of Assuan.
*
- * GnuPG is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Assuan is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
*
- * GnuPG is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Assuan is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include "assuan-defs.h"
@@ -29,13 +30,10 @@
#include "../jnlib/logging.h"
#endif
-
static void *(*alloc_func)(size_t n) = malloc;
static void *(*realloc_func)(void *p, size_t n) = realloc;
static void (*free_func)(void*) = free;
-
-
void
assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
void *(*new_realloc_func)(void *p, size_t n),
@@ -74,7 +72,6 @@ _assuan_free (void *p)
free_func (p);
}
-
/* Store the error in the context so that the error sending function
can take out a descriptive text. Inside the assuan code, use the
@@ -131,6 +128,8 @@ assuan_end_confidential (ASSUAN_CONTEXT ctx)
}
}
+/* Dump a possibly binary string (used for debugging). Distinguish
+ ascii text from binary and print it accordingly. */
void
_assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length)
{
@@ -138,26 +137,31 @@ _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length)
int n;
for (n=length,s=buffer; n; n--, s++)
- {
- if (*s < ' ' || (*s >= 0x7f && *s <= 0xa0))
- break;
- }
+ if (!isascii (*s) || iscntrl (*s) || !isprint (*s))
+ break;
+
s = buffer;
if (!n && *s != '[')
fwrite (buffer, length, 1, fp);
else
{
- putc ('[', fp);
+#ifdef HAVE_FLOCKFILE
+ flockfile (fp);
+#endif
+ putc_unlocked ('[', fp);
for (n=0; n < length; n++, s++)
fprintf (fp, " %02x", *s);
- putc (' ', fp);
- putc (']', fp);
+ putc_unlocked (' ', fp);
+ putc_unlocked (']', fp);
+#ifdef HAVE_FUNLOCKFILE
+ funlockfile (fp);
+#endif
}
}
-/* print a user supplied string after filtering out potential bad
- characters*/
+/* Log a user supplied string. Escapes non-printable before
+ printing. */
void
_assuan_log_sanitized_string (const char *string)
{
@@ -168,29 +172,59 @@ _assuan_log_sanitized_string (const char *string)
FILE *fp = stderr;
#endif
+ if (! *s)
+ return;
+
+#ifdef HAVE_FLOCKFILE
+ flockfile (fp);
+#endif
+
for (; *s; s++)
{
- if (*s < 0x20 || (*s >= 0x7f && *s <= 0xa0))
- {
- putc ('\\', fp);
- if (*s == '\n')
- putc ('n', fp);
- else if (*s == '\r')
- putc ('r', fp);
- else if (*s == '\f')
- putc ('f', fp);
- else if (*s == '\v')
- putc ('v', fp);
- else if (*s == '\b')
- putc ('b', fp);
- else if (!*s)
- putc ('0', fp);
- else
- fprintf (fp, "x%02x", *s );
+ int c = 0;
+
+ switch (*s)
+ {
+ case '\r':
+ c = 'r';
+ break;
+
+ case '\n':
+ c = 'n';
+ break;
+
+ case '\f':
+ c = 'f';
+ break;
+
+ case '\v':
+ c = 'v';
+ break;
+
+ case '\b':
+ c = 'b';
+ break;
+
+ default:
+ if (isascii (*s) && isprint (*s))
+ putc_unlocked (*s, fp);
+ else
+ {
+ putc_unlocked ('\\', fp);
+ fprintf (fp, "x%02x", *s);
+ }
+ }
+
+ if (c)
+ {
+ putc_unlocked ('\\', fp);
+ putc_unlocked (c, fp);
}
- else
- putc (*s, fp);
}
+
+#ifdef HAVE_FUNLOCKFILE
+ funlockfile (fp);
+#endif
}