aboutsummaryrefslogtreecommitdiffstats
path: root/jnlib
diff options
context:
space:
mode:
Diffstat (limited to 'jnlib')
-rw-r--r--jnlib/ChangeLog38
-rw-r--r--jnlib/argparse.c10
-rw-r--r--jnlib/logging.c46
-rw-r--r--jnlib/logging.h2
-rw-r--r--jnlib/stringhelp.c66
-rw-r--r--jnlib/stringhelp.h7
6 files changed, 161 insertions, 8 deletions
diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog
index b5f723cf..bf5e6c7e 100644
--- a/jnlib/ChangeLog
+++ b/jnlib/ChangeLog
@@ -1,3 +1,33 @@
+2002-04-04 Werner Koch <[email protected]>
+
+ * logging.c (log_get_prefix): New.
+
+2002-03-15 Werner Koch <[email protected]>
+
+ * argparse.c (optfile_parse): Fixed missing argument handling.
+
+2002-02-25 Werner Koch <[email protected]>
+
+ * stringhelp.c (ascii_memcasemem): New.
+
+2002-02-14 Werner Koch <[email protected]>
+
+ * Makefile.am (INCLUDES): Add cflags for libgcrypt.
+
+2002-02-07 Werner Koch <[email protected]>
+
+ * logging.c (log_set_fd): New.
+
+ * stringhelp.c (print_sanitized_buffer): New.
+ (print_sanitized_string): New.
+
+2002-01-24 Werner Koch <[email protected]>
+
+ * argparse.c (strusage): Set default copyright notice year to 2002.
+
+ Fixed the copyright notice of this file, as it has always been
+ part of GnuPG and therefore belongs to the FSF.
+
2001-11-01 Marcus Brinkmann <[email protected]>
* logging.c (log_printf): Do not initialize ARG_PTR with 0, we
@@ -72,8 +102,12 @@ Mon Jan 24 13:04:28 CET 2000 Werner Koch <[email protected]>
(do_logv): Add kludge to insert LFs.
- Copyright 2000 Werner Koch (dd9jn)
- Copyright 2001 g10 Code GmbH
+ ***********************************************************
+ * Please note that Jnlib is maintained as part of GnuPG. *
+ * You may find it source-copied in other packages. *
+ ***********************************************************
+
+ Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
This file is free software; as a special exception the author gives
unlimited permission to copy and/or distribute it, with or without
diff --git a/jnlib/argparse.c b/jnlib/argparse.c
index 0e353e4d..0eb99d45 100644
--- a/jnlib/argparse.c
+++ b/jnlib/argparse.c
@@ -276,10 +276,12 @@ optfile_parse( FILE *fp, const char *filename, unsigned *lineno,
arg->r_opt = -arg->r_opt;
if( !opts[idx].short_opt ) /* unknown command/option */
arg->r_opt = (opts[idx].flags & 256)? -7:-2;
- else if( (opts[idx].flags & 8) ) /* no argument */
- arg->r_opt = -3; /* error */
- else /* no or optional argument */
+ else if( !(opts[idx].flags & 7) ) /* does not take an arg */
arg->r_type = 0; /* okay */
+ else if( (opts[idx].flags & 8) ) /* argument is optional */
+ arg->r_type = 0; /* okay */
+ else /* required argument */
+ arg->r_opt = -3; /* error */
break;
}
else if( state == 3 ) { /* no argument found */
@@ -900,7 +902,7 @@ strusage( int level )
switch( level ) {
case 11: p = "foo"; break;
case 13: p = "0.0"; break;
- case 14: p = "Copyright (C) 2001 Free Software Foundation, Inc."; break;
+ case 14: p = "Copyright (C) 2002 Free Software Foundation, Inc."; break;
case 15: p =
"This program comes with ABSOLUTELY NO WARRANTY.\n"
"This is free software, and you are welcome to redistribute it\n"
diff --git a/jnlib/logging.c b/jnlib/logging.c
index 2e0d53ae..647e757c 100644
--- a/jnlib/logging.c
+++ b/jnlib/logging.c
@@ -89,12 +89,37 @@ log_set_file( const char *name )
}
setvbuf( fp, NULL, _IOLBF, 0 );
- if( logstream && logstream != stderr )
- fclose( logstream );
+ if (logstream && logstream != stderr && logstream != stdout)
+ fclose( logstream );
logstream = fp;
missing_lf = 0;
}
+void
+log_set_fd (int fd)
+{
+ FILE *fp;
+
+ if (fd == 1)
+ fp = stdout;
+ else if (fd == 2)
+ fp = stderr;
+ else
+ fp = fdopen (fd, "a");
+ if (!fp)
+ {
+ fprintf (stderr, "failed to fdopen log fd %d: %s\n",
+ fd, strerror(errno));
+ return;
+ }
+ setvbuf (fp, NULL, _IOLBF, 0);
+
+ if (logstream && logstream != stderr && logstream != stdout)
+ fclose( logstream);
+ logstream = fp;
+ missing_lf = 0;
+}
+
void
log_set_prefix (const char *text, unsigned int flags)
@@ -110,6 +135,23 @@ log_set_prefix (const char *text, unsigned int flags)
with_pid = (flags & 4);
}
+
+const char *
+log_get_prefix (unsigned int *flags)
+{
+ if (flags)
+ {
+ *flags = 0;
+ if (with_prefix)
+ *flags |= 1;
+ if (with_time)
+ *flags |= 2;
+ if (with_pid)
+ *flags |=4;
+ }
+ return prefix_buffer;
+}
+
int
log_get_fd()
{
diff --git a/jnlib/logging.h b/jnlib/logging.h
index 7b7b8c8a..224db36e 100644
--- a/jnlib/logging.h
+++ b/jnlib/logging.h
@@ -27,7 +27,9 @@
int log_get_errorcount (int clear);
void log_set_file( const char *name );
+void log_set_fd (int fd);
void log_set_prefix (const char *text, unsigned int flags);
+const char *log_get_prefix (unsigned int *flags);
int log_get_fd(void);
FILE *log_get_stream (void);
diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c
index 0d3035e8..d6883e7d 100644
--- a/jnlib/stringhelp.c
+++ b/jnlib/stringhelp.c
@@ -263,6 +263,52 @@ compare_filenames( const char *a, const char *b )
#endif
}
+/* Print a BUFFER to stream FP while replacing all control characters
+ and the character DELIM with standard C eescape sequences. Returns
+ the number of characters printed. */
+size_t
+print_sanitized_buffer (FILE *fp, const void *buffer, size_t length, int delim)
+{
+ const unsigned char *p = buffer;
+ size_t count = 0;
+
+ for (; length; length--, p++, count++)
+ {
+ if (*p < 0x20 || (*p >= 0x7f && *p < 0xa0) || *p == delim)
+ {
+ putc ('\\', fp);
+ count++;
+ if (*p == '\n')
+ putc ('n', fp);
+ else if (*p == '\r')
+ putc ('r', fp);
+ else if (*p == '\f')
+ putc ('f', fp);
+ else if (*p == '\v')
+ putc ('v', fp);
+ else if (*p == '\b')
+ putc ('b', fp);
+ else if (!*p)
+ putc('0', fp);
+ else
+ {
+ fprintf (fp, "x%02x", *p);
+ count += 2;
+ }
+ }
+ else
+ putc (*p, fp);
+ }
+
+ return count;
+}
+
+size_t
+print_sanitized_string (FILE *fp, const char *string, int delim)
+{
+ return string? print_sanitized_buffer (fp, string, strlen (string), delim):0;
+}
+
/****************************************************
******** locale insensitive ctype functions ********
@@ -336,6 +382,26 @@ ascii_strcmp( const char *a, const char *b )
}
+void *
+ascii_memcasemem (const void *haystack, size_t nhaystack,
+ const void *needle, size_t nneedle)
+{
+
+ if (!nneedle)
+ return (void*)haystack; /* finding an empty needle is really easy */
+ if (nneedle <= nhaystack)
+ {
+ const unsigned char *a = haystack;
+ const unsigned char *b = a + nhaystack - nneedle;
+
+ for (; a <= b; a++)
+ {
+ if ( !ascii_memcasecmp (a, needle, nneedle) )
+ return (void *)a;
+ }
+ }
+ return NULL;
+}
/*********************************************
********** missing string functions *********
diff --git a/jnlib/stringhelp.h b/jnlib/stringhelp.h
index 17a6ad09..bfdb0d91 100644
--- a/jnlib/stringhelp.h
+++ b/jnlib/stringhelp.h
@@ -37,6 +37,11 @@ char *make_dirname(const char *filepath);
char *make_filename( const char *first_part, ... );
int compare_filenames( const char *a, const char *b );
+size_t print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
+ int delim);
+size_t print_sanitized_string (FILE *fp, const char *string, int delim);
+
+
const char *ascii_memistr( const char *buf, size_t buflen, const char *sub );
int ascii_isupper (int c);
int ascii_islower (int c);
@@ -44,6 +49,8 @@ int ascii_toupper (int c);
int ascii_tolower (int c);
int ascii_strcasecmp( const char *a, const char *b );
int ascii_memcasecmp( const char *a, const char *b, size_t n );
+void *ascii_memcasemem (const void *haystack, size_t nhaystack,
+ const void *needle, size_t nneedle);
#ifndef HAVE_MEMICMP