[svn] dirmngr - r234 - in trunk: . jnlib
svn author wk
cvs at cvs.gnupg.org
Mon Sep 4 18:39:01 CEST 2006
Author: wk
Date: 2006-09-04 18:39:01 +0200 (Mon, 04 Sep 2006)
New Revision: 234
Modified:
trunk/ChangeLog
trunk/NEWS
trunk/TODO
trunk/configure.ac
trunk/jnlib/ChangeLog
trunk/jnlib/argparse.c
trunk/jnlib/argparse.h
trunk/jnlib/dotlock.c
trunk/jnlib/dotlock.h
trunk/jnlib/libjnlib-config.h
trunk/jnlib/logging.c
trunk/jnlib/logging.h
trunk/jnlib/mischelp.h
trunk/jnlib/stringhelp.c
trunk/jnlib/stringhelp.h
trunk/jnlib/strlist.c
trunk/jnlib/strlist.h
trunk/jnlib/types.h
trunk/jnlib/utf8conv.c
trunk/jnlib/utf8conv.h
trunk/jnlib/xmalloc.c
trunk/jnlib/xmalloc.h
Log:
Updated jnlib
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/ChangeLog 2006-09-04 16:39:01 UTC (rev 234)
@@ -1,5 +1,7 @@
2006-09-04 Werner Koch <wk at g10code.com>
+ Released 0.9.6.
+
* doc/Makefile.am (dirmngr_TEXINFOS): Do not distribute the fdl.texi.
2006-08-31 Werner Koch <wk at g10code.com>
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/NEWS 2006-09-04 16:39:01 UTC (rev 234)
@@ -1,16 +1,16 @@
-Noteworthy changes in version 0.9.6
+Noteworthy changes in version 0.9.6 (2006-09-04)
------------------------------------------------
* A couple of bug fixes for OCSP.
- * OCSP does not make use of the responder ID and optionally included
- certificates in the response to locate certificate.
+ * OCSP does now make use of the responder ID and optionally included
+ certificates in the response to locate certificates.
* No more lost file descriptors when loading CRLs via HTTP.
* HTTP redirection for CRL and OCSP has been implemented.
- * Man pages are now build and installed from the texinfo sources.
+ * Man pages are now build and installed from the texinfo source.
Noteworthy changes in version 0.9.5 (2006-06-27)
Modified: trunk/TODO
===================================================================
--- trunk/TODO 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/TODO 2006-09-04 16:39:01 UTC (rev 234)
@@ -24,7 +24,7 @@
* Various problems with German SigG certs
We need to implement the chain-validation-model and come up with a
- way to verify the intermediate certificates. Tehre are no CRLs
+ way to verify the intermediate certificates. There are no CRLs
available and using OCSP with the same responder is point less.
Needs more investigation.
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/configure.ac 2006-09-04 16:39:01 UTC (rev 234)
@@ -23,7 +23,7 @@
AC_PREREQ(2.59)
min_automake_version="1.9.3"
-AC_INIT(dirmngr, 0.9.6-cvs, gpa-dev at gnupg.org)
+AC_INIT(dirmngr, 0.9.6, gpa-dev at gnupg.org)
NEED_GPG_ERROR_VERSION=1.0
Modified: trunk/jnlib/ChangeLog
===================================================================
--- trunk/jnlib/ChangeLog 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/ChangeLog 2006-09-04 16:39:01 UTC (rev 234)
@@ -1,3 +1,56 @@
+2006-09-04 Werner Koch <wk at g10code.com>
+
+ Updated to current jnlib version of GnuPG SVN revision 4236.
+
+ * logging.c (do_logv): Emit a missing LF for fatal errors.
+
+ * dotlock.c (make_dotlock, release_dotlock, read_lockfile)
+ (maybe_deadlock, destroy_dotlock, create_dotlock): Re-indented.
+ (create_dotlock): Repalces some log_fatal by log_error as it was
+ not intended that they should terminate. Write the nodename to
+ the locking file. Code cleanups.
+ (read_lockfile): Reworked to read the node name.
+ (make_dotlock): Test for identical node name and delete lock stale
+ file.
+ (release_dotlock): Likewise.
+
+ * libjnlib-config.h (JNLIB_NEED_UTF8CONV): Fixed typo in name.
+
+ * dotlock.c (release_dotlock): Don't act if we don't have any
+ locks at all.
+ (destroy_dotlock): New. From 1.4.3.
+ (dotlock_remove_lockfiles): Make use of destroy function.
+
+ * strlist.c (append_to_strlist2): Enabled.
+
+ * stringhelp.c (print_sanitized_buffer2): New. Changed the rules
+ to match the behaviour of print_string2 from gnupg 1.4.3.
+ (print_sanitized_buffer): Use the new function.
+ (print_sanitized_string2): New.
+ (hextobyte): New. Taken from gpg 1.4.3.
+
+ * stringhelp.c (print_sanitized_buffer): Fix bug where the count
+ got wrong for the \xNN representation.
+ (sanitize_buffer): Fix bug where some control characters lose part
+ of their \xNN representation.
+
+ * stringhelp.c (make_basename): New arg INPUTPATH for future
+ riscos compatibility.
+
+ * libjnlib-config.h (JNLIB_NEED_UTF8CONF): Defined.
+ * strlist.c (add_to_strlist2) [JNLIB_NEED_UTF8CONV]: Enabled.
+
+ * stringhelp.c (sanitize_buffer): Make P a void*.
+ (ascii_memistr, memistr): Ditto.
+ (ascii_memcasecmp): Ditto.
+ * logging.c (writen): Use void * for arg BUFFER.
+ * stringhelp.c (memistr): Fixed unsigned/signed pointer conflict.
+ (ascii_memistr): Ditto.
+ (ascii_memcasemem): Ditto.
+ * utf8conv.c (utf8_to_native): Ditto.
+ (utf8_to_native): Ditto.
+ * argparse.c (show_version): Removed non-required cast.
+
2005-01-19 Werner Koch <wk at g10code.com>
* logging.c (fun_writer): Don't fallback to stderr. Print to
Modified: trunk/jnlib/argparse.c
===================================================================
--- trunk/jnlib/argparse.c 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/argparse.c 2006-09-04 16:39:01 UTC (rev 234)
@@ -1,21 +1,22 @@
/* [argparse.c wk 17.06.97] Argument Parser for option handling
* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
*
- * This file is part of GnuPG.
+ * This file is part of GnuPG.
*
- * 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.
+ * 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.
*
- * 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.
+ * 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.
*
- * 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#include <config.h>
@@ -852,7 +853,7 @@
/* additional program info */
for(i=30; i < 40; i++ )
if( (s=strusage(i)) )
- fputs( (const byte*)s, stdout);
+ fputs (s, stdout);
fflush(stdout);
}
@@ -904,7 +905,7 @@
switch( level ) {
case 11: p = "foo"; break;
case 13: p = "0.0"; break;
- case 14: p = "Copyright (C) 2005 Free Software Foundation, Inc."; break;
+ case 14: p = "Copyright (C) 2006 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"
@@ -920,7 +921,8 @@
"GNU General Public License for more details.\n\n"
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n"
-"Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n";
+"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,\n"
+"USA.\n";
break;
case 40: /* short and long usage */
case 41: p = ""; break;
Modified: trunk/jnlib/argparse.h
===================================================================
--- trunk/jnlib/argparse.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/argparse.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#ifndef LIBJNLIB_ARGPARSE_H
Modified: trunk/jnlib/dotlock.c
===================================================================
--- trunk/jnlib/dotlock.c 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/dotlock.c 2006-09-04 16:39:01 UTC (rev 234)
@@ -1,5 +1,6 @@
/* dotlock.c - dotfile locking
- * Copyright (C) 1998,2000,2001,2003 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 2000, 2001, 2003, 2004,
+ * 2005, 2006 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -15,7 +16,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#include <config.h>
@@ -53,32 +55,35 @@
#endif
-struct dotlock_handle {
- struct dotlock_handle *next;
- char *tname; /* name of lockfile template */
- char *lockname; /* name of the real lockfile */
- int locked; /* lock status */
- int disable; /* locking */
+struct dotlock_handle
+{
+ struct dotlock_handle *next;
+ char *tname; /* Name of lockfile template. */
+ size_t nodename_off; /* Offset in TNAME of the nodename part. */
+ size_t nodename_len; /* Length of the nodename part. */
+ char *lockname; /* Name of the real lockfile. */
+ int locked; /* Lock status. */
+ int disable; /* When true, locking is disabled. */
};
static volatile DOTLOCK all_lockfiles;
static int never_lock;
-static int read_lockfile( const char *name );
+static int read_lockfile (DOTLOCK h, int *same_node);
void
disable_dotlock(void)
{
- never_lock = 1;
+ never_lock = 1;
}
/****************
* Create a lockfile with the given name and return an object of
* type DOTLOCK which may be used later to actually do the lock.
* A cleanup routine gets installed to cleanup left over locks
- * or other files used together with the lockmechanism.
- * Althoug the function is called dotlock, this does not necessarily
+ * or other files used together with the lock mechanism.
+ * Although the function is called dotlock, this does not necessarily
* mean that real lockfiles are used - the function may decide to
* use fcntl locking. Calling the function with NULL only install
* the atexit handler and maybe used to assure that the cleanup
@@ -92,229 +97,286 @@
DOTLOCK
create_dotlock( const char *file_to_lock )
{
- static int initialized;
- DOTLOCK h;
- int fd = -1;
- char pidstr[16];
- #ifndef HAVE_DOSISH_SYSTEM
- struct utsname utsbuf;
- #endif
- const char *nodename;
- const char *dirpart;
- int dirpartlen;
+ static int initialized;
+ DOTLOCK h;
+ int fd = -1;
+ char pidstr[16];
+ const char *nodename;
+ const char *dirpart;
+ int dirpartlen;
+#ifndef HAVE_DOSISH_SYSTEM
+ struct utsname utsbuf;
+#endif
- if( !initialized ) {
- atexit( dotlock_remove_lockfiles );
- initialized = 1;
+ if ( !initialized )
+ {
+ atexit( dotlock_remove_lockfiles );
+ initialized = 1;
}
- if( !file_to_lock )
- return NULL;
+ if ( !file_to_lock )
+ return NULL; /* Only initialization was requested. */
- h = jnlib_xcalloc( 1, sizeof *h );
- if( never_lock ) {
- h->disable = 1;
+ h = jnlib_xcalloc ( 1, sizeof *h );
+ if( never_lock )
+ {
+ h->disable = 1;
#ifdef _REENTRANT
- /* fixme: aquire mutex on all_lockfiles */
+ /* fixme: aquire mutex on all_lockfiles */
#endif
- h->next = all_lockfiles;
- all_lockfiles = h;
- return h;
+ h->next = all_lockfiles;
+ all_lockfiles = h;
+ return h;
}
#ifndef HAVE_DOSISH_SYSTEM
- sprintf( pidstr, "%10d\n", (int)getpid() );
- /* fixme: add the hostname to the second line (FQDN or IP addr?) */
+ sprintf (pidstr, "%10d\n", (int)getpid() );
+ /* fixme: add the hostname to the second line (FQDN or IP addr?) */
- /* create a temporary file */
- if( uname( &utsbuf ) )
- nodename = "unknown";
- else
- nodename = utsbuf.nodename;
-
+ /* Create a temporary file. */
+ if ( uname ( &utsbuf ) )
+ nodename = "unknown";
+ else
+ nodename = utsbuf.nodename;
+
#ifdef __riscos__
- {
- char *iter = (char *) nodename;
- for (; iter[0]; iter++)
- if (iter[0] == '.')
- iter[0] = '/';
- }
+ {
+ char *iter = (char *) nodename;
+ for (; iter[0]; iter++)
+ if (iter[0] == '.')
+ iter[0] = '/';
+ }
#endif /* __riscos__ */
- if( !(dirpart = strrchr( file_to_lock, DIRSEP_C )) ) {
- dirpart = EXTSEP_S;
- dirpartlen = 1;
+ if ( !(dirpart = strrchr ( file_to_lock, DIRSEP_C )) )
+ {
+ dirpart = EXTSEP_S;
+ dirpartlen = 1;
}
- else {
- dirpartlen = dirpart - file_to_lock;
- dirpart = file_to_lock;
+ else
+ {
+ dirpartlen = dirpart - file_to_lock;
+ dirpart = file_to_lock;
}
- #ifdef _REENTRANT
+#ifdef _REENTRANT
/* fixme: aquire mutex on all_lockfiles */
- #endif
- h->next = all_lockfiles;
- all_lockfiles = h;
+#endif
+ h->next = all_lockfiles;
+ all_lockfiles = h;
- h->tname = jnlib_xmalloc( dirpartlen + 6+30+ strlen(nodename) + 11 );
+ h->tname = jnlib_xmalloc ( dirpartlen + 6+30+ strlen(nodename) + 11 );
+ h->nodename_len = strlen (nodename);
#ifndef __riscos__
- sprintf( h->tname, "%.*s/.#lk%p.%s.%d",
- dirpartlen, dirpart, h, nodename, (int)getpid() );
+ sprintf (h->tname, "%.*s/.#lk%p.", dirpartlen, dirpart, h );
+ h->nodename_off = strlen (h->tname);
+ sprintf (h->tname+h->nodename_off, "%s.%d", nodename, (int)getpid ());
#else /* __riscos__ */
- sprintf( h->tname, "%.*s.lk%p/%s/%d",
- dirpartlen, dirpart, h, nodename, (int)getpid() );
+ sprintf (h->tname, "%.*s.lk%p/", dirpartlen, dirpart, h );
+ h->nodename_off = strlen (h->tname);
+ sprintf (h->tname+h->nodename_off, "%s/%d", nodename, (int)getpid () );
#endif /* __riscos__ */
- do {
- errno = 0;
- fd = open( h->tname, O_WRONLY|O_CREAT|O_EXCL,
- S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR );
- } while( fd == -1 && errno == EINTR );
- if( fd == -1 ) {
- all_lockfiles = h->next;
- log_error( "failed to create temporary file `%s': %s\n",
- h->tname, strerror(errno));
- jnlib_free(h->tname);
- jnlib_free(h);
- return NULL;
+ do
+ {
+ errno = 0;
+ fd = open (h->tname, O_WRONLY|O_CREAT|O_EXCL,
+ S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR );
+ }
+ while (fd == -1 && errno == EINTR);
+
+ if ( fd == -1 )
+ {
+ all_lockfiles = h->next;
+ log_error ( "failed to create temporary file `%s': %s\n",
+ h->tname, strerror(errno));
+ jnlib_free(h->tname);
+ jnlib_free(h);
+ return NULL;
}
- if( write(fd, pidstr, 11 ) != 11 ) {
- all_lockfiles = h->next;
- #ifdef _REENTRANT
- /* release mutex */
- #endif
- log_fatal( "error writing to `%s': %s\n", h->tname, strerror(errno) );
- close(fd);
- unlink(h->tname);
- jnlib_free(h->tname);
- jnlib_free(h);
- return NULL;
- }
- if( close(fd) ) {
- all_lockfiles = h->next;
- #ifdef _REENTRANT
- /* release mutex */
- #endif
- log_fatal( "error writing to `%s': %s\n", h->tname, strerror(errno) );
- close(fd);
- unlink(h->tname);
- jnlib_free(h->tname);
- jnlib_free(h);
- return NULL;
- }
+ if ( write (fd, pidstr, 11 ) != 11 )
+ goto write_failed;
+ if ( write (fd, nodename, strlen (nodename) ) != strlen (nodename) )
+ goto write_failed;
+ if ( write (fd, "\n", 1 ) != 1 )
+ goto write_failed;
+ if ( close (fd) )
+ goto write_failed;
- #ifdef _REENTRANT
- /* release mutex */
- #endif
+# ifdef _REENTRANT
+ /* release mutex */
+# endif
#endif /* !HAVE_DOSISH_SYSTEM */
- h->lockname = jnlib_xmalloc( strlen(file_to_lock) + 6 );
- strcpy(stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock");
- return h;
+ h->lockname = jnlib_xmalloc ( strlen (file_to_lock) + 6 );
+ strcpy (stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock");
+ return h;
+ write_failed:
+ all_lockfiles = h->next;
+# ifdef _REENTRANT
+ /* fixme: release mutex */
+# endif
+ log_error ( "error writing to `%s': %s\n", h->tname, strerror(errno) );
+ close(fd);
+ unlink(h->tname);
+ jnlib_free(h->tname);
+ jnlib_free(h);
+ return NULL;
}
+
+void
+destroy_dotlock ( DOTLOCK h )
+{
+#ifndef HAVE_DOSISH_SYSTEM
+ if ( h )
+ {
+ DOTLOCK hprev, htmp;
+
+ /* First remove the handle from our global list of all locks. */
+ for (hprev=NULL, htmp=all_lockfiles; htmp; hprev=htmp, htmp=htmp->next)
+ if (htmp == h)
+ {
+ if (hprev)
+ hprev->next = htmp->next;
+ else
+ all_lockfiles = htmp->next;
+ h->next = NULL;
+ break;
+ }
+
+ /* Second destroy the lock. */
+ if (!h->disable)
+ {
+ if (h->locked && h->lockname)
+ unlink (h->lockname);
+ if (h->tname)
+ unlink (h->tname);
+ jnlib_free (h->tname);
+ jnlib_free (h->lockname);
+ }
+ jnlib_free(h);
+ }
+#endif /*!HAVE_DOSISH_SYSTEM*/
+}
+
+
+
static int
maybe_deadlock( DOTLOCK h )
{
- DOTLOCK r;
+ DOTLOCK r;
- for( r=all_lockfiles; r; r = r->next ) {
- if( r != h && r->locked )
- return 1;
+ for ( r=all_lockfiles; r; r = r->next )
+ {
+ if ( r != h && r->locked )
+ return 1;
}
- return 0;
+ return 0;
}
/****************
- * Do a lock on H. A TIMEOUT of 0 returns immediately,
- * -1 waits forever (hopefully not), other
- * values are timeouts in milliseconds.
- * Returns: 0 on success
+ * Do a lock on H. A TIMEOUT of 0 returns immediately, -1 waits
+ * forever (hopefully not), other values are reserved (should then be
+ * timeouts in milliseconds). Returns: 0 on success
*/
int
make_dotlock( DOTLOCK h, long timeout )
{
#ifdef HAVE_DOSISH_SYSTEM
- return 0;
+ return 0;
#else
- int pid;
- const char *maybe_dead="";
- int backoff=0;
+ int pid;
+ const char *maybe_dead="";
+ int backoff=0;
+ int same_node;
- if( h->disable ) {
- return 0;
- }
+ if ( h->disable )
+ return 0; /* Locks are completely disabled. Return success. */
- if( h->locked ) {
+ if ( h->locked )
+ {
#ifndef __riscos__
- log_debug("oops, `%s' is already locked\n", h->lockname );
+ log_debug("oops, `%s' is already locked\n", h->lockname );
#endif /* !__riscos__ */
- return 0;
+ return 0;
}
- for(;;) {
+ for(;;)
+ {
#ifndef __riscos__
- if( !link(h->tname, h->lockname) ) {
- /* fixme: better use stat to check the link count */
- h->locked = 1;
- return 0; /* okay */
+ if ( !link(h->tname, h->lockname) )
+ {
+ /* fixme: better use stat to check the link count */
+ h->locked = 1;
+ return 0; /* okay */
}
- if( errno != EEXIST ) {
- log_error( "lock not made: link() failed: %s\n", strerror(errno) );
- return -1;
+ if ( errno != EEXIST )
+ {
+ log_error( "lock not made: link() failed: %s\n", strerror(errno) );
+ return -1;
}
#else /* __riscos__ */
- if( !renamefile(h->tname, h->lockname) ) {
- h->locked = 1;
- return 0; /* okay */
+ if ( !renamefile(h->tname, h->lockname) )
+ {
+ h->locked = 1;
+ return 0; /* okay */
}
- if( errno != EEXIST ) {
- log_error( "lock not made: rename() failed: %s\n", strerror(errno) );
- return -1;
+ if ( errno != EEXIST )
+ {
+ log_error( "lock not made: rename() failed: %s\n", strerror(errno) );
+ return -1;
}
#endif /* __riscos__ */
- if( (pid = read_lockfile(h->lockname)) == -1 ) {
- if( errno != ENOENT ) {
- log_info("cannot read lockfile\n");
- return -1;
+
+ if ( (pid = read_lockfile (h, &same_node)) == -1 )
+ {
+ if ( errno != ENOENT )
+ {
+ log_info ("cannot read lockfile\n");
+ return -1;
}
- log_info( "lockfile disappeared\n");
- continue;
+ log_info( "lockfile disappeared\n");
+ continue;
}
- else if( pid == getpid() ) {
- log_info( "Oops: lock already held by us\n");
- h->locked = 1;
- return 0; /* okay */
+ else if ( pid == getpid() && same_node )
+ {
+ log_info( "Oops: lock already held by us\n");
+ h->locked = 1;
+ return 0; /* okay */
}
- else if( kill(pid, 0) && errno == ESRCH ) {
+ else if ( same_node && kill (pid, 0) && errno == ESRCH )
+ {
#ifndef __riscos__
- maybe_dead = " - probably dead";
-#if 0 /* we should not do this without checking the permissions */
- /* and the hostname */
- log_info( "removing stale lockfile (created by %d)", pid );
-#endif
+ log_info ("removing stale lockfile (created by %d)", pid );
+ unlink (h->lockname);
+ continue;
#else /* __riscos__ */
- /* we are *pretty* sure that the other task is dead and therefore
- we remove the other lock file */
- maybe_dead = " - probably dead - removing lock";
- unlink(h->lockname);
+ /* Under RISCOS we are *pretty* sure that the other task
+ is dead and therefore we remove the stale lock file. */
+ maybe_dead = " - probably dead - removing lock";
+ unlink(h->lockname);
#endif /* __riscos__ */
}
- if( timeout == -1 ) {
- struct timeval tv;
- log_info( "waiting for lock (held by %d%s) %s...\n",
- pid, maybe_dead, maybe_deadlock(h)? "(deadlock?) ":"");
+ if ( timeout == -1 )
+ {
+ /* Wait until lock has been released. */
+ struct timeval tv;
+
+ log_info ("waiting for lock (held by %d%s) %s...\n",
+ pid, maybe_dead, maybe_deadlock(h)? "(deadlock?) ":"");
- /* can't use sleep, cause signals may be blocked */
- tv.tv_sec = 1 + backoff;
- tv.tv_usec = 0;
- select(0, NULL, NULL, NULL, &tv);
- if( backoff < 10 )
- backoff++ ;
+
+ /* We can't use sleep, cause signals may be blocked. */
+ tv.tv_sec = 1 + backoff;
+ tv.tv_usec = 0;
+ select(0, NULL, NULL, NULL, &tv);
+ if ( backoff < 10 )
+ backoff++ ;
}
- else
- return -1;
+ else
+ return -1;
}
- /*not reached */
+ /*NOTREACHED*/
#endif /* !HAVE_DOSISH_SYSTEM */
}
@@ -327,85 +389,150 @@
release_dotlock( DOTLOCK h )
{
#ifdef HAVE_DOSISH_SYSTEM
- return 0;
+ return 0;
#else
- int pid;
+ int pid, same_node;
- if( h->disable ) {
- return 0;
- }
+ /* To avoid atexit race conditions we first check whether there are
+ any locks left. It might happen that another atexit handler
+ tries to release the lock while the atexit handler of this module
+ already ran and thus H is undefined. */
+ if (!all_lockfiles)
+ return 0;
- if( !h->locked ) {
- log_debug("oops, `%s' is not locked\n", h->lockname );
- return 0;
+ if ( h->disable )
+ return 0;
+
+ if ( !h->locked )
+ {
+ log_debug("oops, `%s' is not locked\n", h->lockname );
+ return 0;
}
- pid = read_lockfile( h->lockname );
- if( pid == -1 ) {
- log_error( "release_dotlock: lockfile error\n");
- return -1;
+ pid = read_lockfile (h, &same_node);
+ if ( pid == -1 )
+ {
+ log_error( "release_dotlock: lockfile error\n");
+ return -1;
}
- if( pid != getpid() ) {
- log_error( "release_dotlock: not our lock (pid=%d)\n", pid);
- return -1;
+ if ( pid != getpid() || !same_node )
+ {
+ log_error( "release_dotlock: not our lock (pid=%d)\n", pid);
+ return -1;
}
#ifndef __riscos__
- if( unlink( h->lockname ) ) {
- log_error( "release_dotlock: error removing lockfile `%s'",
- h->lockname);
- return -1;
+ if ( unlink( h->lockname ) )
+ {
+ log_error( "release_dotlock: error removing lockfile `%s'",
+ h->lockname);
+ return -1;
}
#else /* __riscos__ */
- if( renamefile(h->lockname, h->tname) ) {
- log_error( "release_dotlock: error renaming lockfile `%s' to `%s'",
- h->lockname, h->tname);
- return -1;
+ if ( renamefile(h->lockname, h->tname) )
+ {
+ log_error( "release_dotlock: error renaming lockfile `%s' to `%s'",
+ h->lockname, h->tname);
+ return -1;
}
#endif /* __riscos__ */
- /* fixme: check that the link count is now 1 */
- h->locked = 0;
- return 0;
+ /* fixme: check that the link count is now 1 */
+ h->locked = 0;
+ return 0;
#endif /* !HAVE_DOSISH_SYSTEM */
}
-/****************
- * Read the lock file and return the pid, returns -1 on error.
+/*
+ Read the lock file and return the pid, returns -1 on error. True
+ will be stored at SAME_NODE if the lock file has been created on
+ the same node.
*/
static int
-read_lockfile( const char *name )
+read_lockfile (DOTLOCK h, int *same_node )
{
#ifdef HAVE_DOSISH_SYSTEM
- return 0;
+ return 0;
#else
- int fd, pid;
- char pidstr[16];
+ char buffer_space[10+1+70+1]; /* 70 is just an estimated value; node
+ name are usually shorter. */
+ int fd, pid;
+ char *buffer, *p;
+ size_t expected_len;
+ int res, nread;
+
+ *same_node = 0;
+ expected_len = 10 + 1 + h->nodename_len + 1;
+ if ( expected_len >= sizeof buffer_space)
+ buffer = jnlib_xmalloc (expected_len);
+ else
+ buffer = buffer_space;
- if( (fd = open(name, O_RDONLY)) == -1 ) {
- int e = errno;
- log_debug("error opening lockfile `%s': %s\n", name, strerror(errno) );
- errno = e;
- return -1;
+ if ( (fd = open (h->lockname, O_RDONLY)) == -1 )
+ {
+ int e = errno;
+ log_info ("error opening lockfile `%s': %s\n",
+ h->lockname, strerror(errno) );
+ if (buffer != buffer_space)
+ jnlib_free (buffer);
+ errno = e; /* Need to return ERRNO here. */
+ return -1;
}
- if( read(fd, pidstr, 10 ) != 10 ) { /* Read 10 digits w/o newline */
- log_debug("error reading lockfile `%s'", name );
- close(fd);
- errno = 0;
- return -1;
+
+ p = buffer;
+ nread = 0;
+ do
+ {
+ res = read (fd, p, expected_len - nread);
+ if (res == -1 && errno == EINTR)
+ continue;
+ if (res < 0)
+ {
+ log_info ("error reading lockfile `%s'", h->lockname );
+ close (fd);
+ if (buffer != buffer_space)
+ jnlib_free (buffer);
+ errno = 0; /* Do not return an inappropriate ERRNO. */
+ return -1;
+ }
+ p += res;
+ nread += res;
}
- pidstr[10] = 0; /* terminate pid string */
- close(fd);
- pid = atoi(pidstr);
+ while (res && nread != expected_len);
+ close(fd);
+
+ if (nread < 11)
+ {
+ log_info ("invalid size of lockfile `%s'", h->lockname );
+ if (buffer != buffer_space)
+ jnlib_free (buffer);
+ errno = 0; /* Do not return an inappropriate ERRNO. */
+ return -1;
+ }
+
+ if (buffer[10] != '\n'
+ || (buffer[10] = 0, pid = atoi (buffer)) == -1
#ifndef __riscos__
- if( !pid || pid == -1 ) {
+ || !pid
#else /* __riscos__ */
- if( (!pid && riscos_getpid()) || pid == -1 ) {
+ || (!pid && riscos_getpid())
#endif /* __riscos__ */
- log_error("invalid pid %d in lockfile `%s'", pid, name );
- errno = 0;
- return -1;
+ )
+ {
+ log_error ("invalid pid %d in lockfile `%s'", pid, h->lockname );
+ if (buffer != buffer_space)
+ jnlib_free (buffer);
+ errno = 0;
+ return -1;
}
- return pid;
+
+ if (nread == expected_len
+ && !memcmp (h->tname+h->nodename_off, buffer+11, h->nodename_len)
+ && buffer[11+h->nodename_len] == '\n')
+ *same_node = 1;
+
+ if (buffer != buffer_space)
+ jnlib_free (buffer);
+ return pid;
#endif
}
@@ -414,22 +541,16 @@
dotlock_remove_lockfiles()
{
#ifndef HAVE_DOSISH_SYSTEM
- DOTLOCK h, h2;
-
- h = all_lockfiles;
- all_lockfiles = NULL;
-
- while( h ) {
- h2 = h->next;
- if (!h->disable ) {
- if( h->locked )
- unlink( h->lockname );
- unlink(h->tname);
- jnlib_free(h->tname);
- jnlib_free(h->lockname);
- }
- jnlib_free(h);
- h = h2;
+ DOTLOCK h, h2;
+
+ h = all_lockfiles;
+ all_lockfiles = NULL;
+
+ while ( h )
+ {
+ h2 = h->next;
+ destroy_dotlock (h);
+ h = h2;
}
#endif
}
Modified: trunk/jnlib/dotlock.h
===================================================================
--- trunk/jnlib/dotlock.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/dotlock.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#ifndef LIBJNLIB_DOTLOCK_H
@@ -26,6 +27,7 @@
void disable_dotlock (void);
DOTLOCK create_dotlock(const char *file_to_lock);
+void destroy_dotlock ( DOTLOCK h );
int make_dotlock (DOTLOCK h, long timeout);
int release_dotlock (DOTLOCK h);
void dotlock_remove_lockfiles (void);
Modified: trunk/jnlib/libjnlib-config.h
===================================================================
--- trunk/jnlib/libjnlib-config.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/libjnlib-config.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
/****************
@@ -29,6 +30,10 @@
#include <gcrypt.h> /* gcry_malloc & Cie. */
#include "logging.h"
+/* We require support for utf-8 conversion. */
+#define JNLIB_NEED_UTF8CONV 1
+
+
#ifdef USE_SIMPLE_GETTEXT
int set_gettext_file( const char *filename );
const char *gettext( const char *msgid );
Modified: trunk/jnlib/logging.c
===================================================================
--- trunk/jnlib/logging.c 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/logging.c 2006-09-04 16:39:01 UTC (rev 234)
@@ -16,7 +16,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
@@ -87,10 +88,11 @@
char name[1];
};
-/* Write NBYTES of BUF to file descriptor FD. */
+/* Write NBYTES of BUFFER to file descriptor FD. */
static int
-writen (int fd, const unsigned char *buf, size_t nbytes)
+writen (int fd, const void *buffer, size_t nbytes)
{
+ const char *buf = buffer;
size_t nleft = nbytes;
int nwritten;
@@ -484,9 +486,17 @@
}
if (level == JNLIB_LOG_FATAL)
- exit(2);
+ {
+ if (missing_lf)
+ putc('\n', logstream );
+ exit(2);
+ }
if (level == JNLIB_LOG_BUG)
- abort();
+ {
+ if (missing_lf)
+ putc('\n', logstream );
+ abort();
+ }
}
static void
Modified: trunk/jnlib/logging.h
===================================================================
--- trunk/jnlib/logging.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/logging.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#ifndef LIBJNLIB_LOGGING_H
Modified: trunk/jnlib/mischelp.h
===================================================================
--- trunk/jnlib/mischelp.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/mischelp.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#ifndef LIBJNLIB_MISCHELP_H
Modified: trunk/jnlib/stringhelp.c
===================================================================
--- trunk/jnlib/stringhelp.c 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/stringhelp.c 2006-09-04 16:39:01 UTC (rev 234)
@@ -1,6 +1,6 @@
/* stringhelp.c - standard string helper functions
- * Copyright (C) 1998, 1999, 2000, 2001, 2003,
- * 2004 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+ * 2006 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -16,7 +16,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#include <config.h>
@@ -35,45 +36,57 @@
/*
* Look for the substring SUB in buffer and return a pointer to that
- * substring in BUF or NULL if not found.
+ * substring in BUFFER or NULL if not found.
* Comparison is case-insensitive.
*/
const char *
-memistr( const char *buf, size_t buflen, const char *sub )
+memistr (const void *buffer, size_t buflen, const char *sub)
{
- const byte *t, *s ;
- size_t n;
+ const unsigned char *buf = buffer;
+ const unsigned char *t = (const unsigned char *)buffer;
+ const unsigned char *s = (const unsigned char *)sub;
+ size_t n = buflen;
- for( t=buf, n=buflen, s=sub ; n ; t++, n-- )
- if( toupper(*t) == toupper(*s) ) {
- for( buf=t++, buflen = n--, s++;
- n && toupper(*t) == toupper(*s); t++, s++, n-- )
- ;
- if( !*s )
- return buf;
- t = buf; n = buflen; s = sub ;
+ for ( ; n ; t++, n-- )
+ {
+ if ( toupper (*t) == toupper (*s) )
+ {
+ for ( buf=t++, buflen = n--, s++;
+ n && toupper (*t) == toupper (*s); t++, s++, n-- )
+ ;
+ if (!*s)
+ return (const char*)buf;
+ t = buf;
+ s = (const unsigned char *)sub ;
+ n = buflen;
}
-
- return NULL ;
+ }
+ return NULL;
}
const char *
-ascii_memistr( const char *buf, size_t buflen, const char *sub )
+ascii_memistr ( const void *buffer, size_t buflen, const char *sub )
{
- const byte *t, *s ;
- size_t n;
+ const unsigned char *buf = buffer;
+ const unsigned char *t = (const unsigned char *)buf;
+ const unsigned char *s = (const unsigned char *)sub;
+ size_t n = buflen;
- for( t=buf, n=buflen, s=sub ; n ; t++, n-- )
- if( ascii_toupper(*t) == ascii_toupper(*s) ) {
- for( buf=t++, buflen = n--, s++;
- n && ascii_toupper(*t) == ascii_toupper(*s); t++, s++, n-- )
- ;
- if( !*s )
- return buf;
- t = buf; n = buflen; s = sub ;
+ for ( ; n ; t++, n-- )
+ {
+ if (ascii_toupper (*t) == ascii_toupper (*s) )
+ {
+ for ( buf=t++, buflen = n--, s++;
+ n && ascii_toupper (*t) == ascii_toupper (*s); t++, s++, n-- )
+ ;
+ if (!*s)
+ return (const char*)buf;
+ t = (const unsigned char *)buf;
+ s = (const unsigned char *)sub ;
+ n = buflen;
}
-
- return NULL ;
+ }
+ return NULL;
}
/* This function is similar to strncpy(). However it won't copy more
@@ -206,8 +219,8 @@
return len;
}
-/****************
- * remove trailing white spaces and return the length of the buffer
+/*
+ * Return the length of line ignoring trailing white-space.
*/
size_t
length_sans_trailing_ws (const unsigned char *line, size_t len)
@@ -222,15 +235,19 @@
*
*/
char *
-make_basename(const char *filepath)
+make_basename(const char *filepath, const char *inputpath)
{
char *p;
+#ifdef __riscos__
+ return riscos_make_basename(filepath, inputpath);
+#endif
+
if ( !(p=strrchr(filepath, '/')) )
- #ifdef HAVE_DRIVE_LETTERS
+#ifdef HAVE_DRIVE_LETTERS
if ( !(p=strrchr(filepath, '\\')) )
if ( !(p=strrchr(filepath, ':')) )
- #endif
+#endif
{
return jnlib_xstrdup(filepath);
}
@@ -320,48 +337,112 @@
#endif
}
+
+/* Convert 2 hex characters at S to a byte value. Return this value
+ or -1 if there is an error. */
+int
+hextobyte (const char *s)
+{
+ int c;
+
+ if ( *s >= '0' && *s <= '9' )
+ c = 16 * (*s - '0');
+ else if ( *s >= 'A' && *s <= 'F' )
+ c = 16 * (10 + *s - 'A');
+ else if ( *s >= 'a' && *s <= 'f' )
+ c = 16 * (10 + *s - 'a');
+ else
+ return -1;
+ s++;
+ if ( *s >= '0' && *s <= '9' )
+ c += *s - '0';
+ else if ( *s >= 'A' && *s <= 'F' )
+ c += 10 + *s - 'A';
+ else if ( *s >= 'a' && *s <= 'f' )
+ c += 10 + *s - 'a';
+ else
+ return -1;
+ return c;
+}
+
+
/* Print a BUFFER to stream FP while replacing all control characters
- and the character DELIM with standard C escape sequences. Returns
- the number of characters printed. */
+ and the characters DELIM and DELIM2 with standard C escape
+ sequences. Returns the number of characters printed. */
size_t
-print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
- int delim)
+print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
+ int delim, int delim2)
{
const unsigned char *p = buffer;
size_t count = 0;
for (; length; length--, p++, count++)
{
- if (*p < 0x20 || *p == 0x7f || *p == delim)
+ /* Fixme: Check whether *p < 0xa0 is correct for utf8 encoding. */
+ if (*p < 0x20
+ || (*p >= 0x7f && *p < 0xa0)
+ || *p == delim
+ || *p == delim2
+ || ((delim || delim2) && *p=='\\'))
{
putc ('\\', fp);
count++;
if (*p == '\n')
- putc ('n', fp);
+ {
+ putc ('n', fp);
+ count++;
+ }
else if (*p == '\r')
- putc ('r', fp);
+ {
+ putc ('r', fp);
+ count++;
+ }
else if (*p == '\f')
- putc ('f', fp);
+ {
+ putc ('f', fp);
+ count++;
+ }
else if (*p == '\v')
- putc ('v', fp);
+ {
+ putc ('v', fp);
+ count++;
+ }
else if (*p == '\b')
- putc ('b', fp);
+ {
+ putc ('b', fp);
+ count++;
+ }
else if (!*p)
- putc('0', fp);
+ {
+ putc('0', fp);
+ count++;
+ }
else
{
fprintf (fp, "x%02x", *p);
- count += 2;
+ count += 3;
}
}
else
- putc (*p, fp);
+ {
+ putc (*p, fp);
+ count++;
+ }
}
return count;
}
+/* Same as print_sanitized_buffer2 but with just one delimiter. */
size_t
+print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
+ int delim)
+{
+ return print_sanitized_buffer2 (fp, buffer, length, delim, 0);
+}
+
+
+size_t
print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
size_t length, int delim)
{
@@ -389,6 +470,13 @@
size_t
+print_sanitized_string2 (FILE *fp, const char *string, int delim, int delim2)
+{
+ return string? print_sanitized_buffer2 (fp, string, strlen (string),
+ delim, delim2):0;
+}
+
+size_t
print_sanitized_string (FILE *fp, const char *string, int delim)
{
return string? print_sanitized_buffer (fp, string, strlen (string), delim):0;
@@ -402,16 +490,17 @@
delim) : 0;
}
-/* Create a string from the buffer P of length N which is suitable for
+/* Create a string from the buffer P_ARG of length N which is suitable for
printing. Caller must release the created string using xfree. */
char *
-sanitize_buffer (const unsigned char *p, size_t n, int delim)
+sanitize_buffer (const void *p_arg, size_t n, int delim)
{
+ const unsigned char *p = p_arg;
size_t save_n, buflen;
- const byte *save_p;
+ const unsigned char *save_p;
char *buffer, *d;
- /* first count length */
+ /* First count length. */
for (save_n = n, save_p = p, buflen=1 ; n; n--, p++ )
{
if ( *p < 0x20 || *p == 0x7f || *p == delim || (delim && *p=='\\'))
@@ -420,14 +509,14 @@
|| *p=='\v' || *p=='\b' || !*p )
buflen += 2;
else
- buflen += 4;
+ buflen += 5;
}
else
buflen++;
}
p = save_p;
n = save_n;
- /* and now make the string */
+ /* And now make the string */
d = buffer = jnlib_xmalloc( buflen );
for ( ; n; n--, p++ )
{
@@ -447,7 +536,7 @@
*d++ = '0';
else {
sprintf(d, "x%02x", *p );
- d += 2;
+ d += 3;
}
}
else
@@ -552,15 +641,19 @@
int
-ascii_memcasecmp( const char *a, const char *b, size_t n )
+ascii_memcasecmp (const void *a_arg, const void *b_arg, size_t n )
{
- if (a == b)
- return 0;
- for ( ; n; n--, a++, b++ ) {
- if( *a != *b && ascii_toupper (*a) != ascii_toupper (*b) )
- return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b));
+ const char *a = a_arg;
+ const char *b = b_arg;
+
+ if (a == b)
+ return 0;
+ for ( ; n; n--, a++, b++ )
+ {
+ if( *a != *b && ascii_toupper (*a) != ascii_toupper (*b) )
+ return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b));
}
- return 0;
+ return 0;
}
int
@@ -586,8 +679,8 @@
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;
+ const char *a = haystack;
+ const char *b = a + nhaystack - nneedle;
for (; a <= b; a++)
{
Modified: trunk/jnlib/stringhelp.h
===================================================================
--- trunk/jnlib/stringhelp.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/stringhelp.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#ifndef LIBJNLIB_STRINGHELP_H
@@ -23,7 +24,7 @@
#include "types.h"
-const char *memistr( const char *buf, size_t buflen, const char *sub );
+const char *memistr (const void *buf, size_t buflen, const char *sub);
char *mem2str( char *, const void *, size_t);
char *trim_spaces( char *string );
char *trim_trailing_spaces( char *string );
@@ -35,18 +36,24 @@
size_t length_sans_trailing_ws (const unsigned char *line, size_t len);
-char *make_basename(const char *filepath);
+char *make_basename(const char *filepath, const char *inputpath);
char *make_dirname(const char *filepath);
char *make_filename( const char *first_part, ... );
int compare_filenames( const char *a, const char *b );
+int hextobyte (const char *s);
+
size_t print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
int delim);
+size_t print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
+ int delim, int delim2);
size_t print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
size_t length, int delim);
size_t print_sanitized_string (FILE *fp, const char *string, int delim);
+size_t print_sanitized_string2 (FILE *fp, const char *string,
+ int delim, int delim2);
size_t print_sanitized_utf8_string (FILE *fp, const char *string, int delim);
-char *sanitize_buffer (const unsigned char *p, size_t n, int delim);
+char *sanitize_buffer (const void *p, size_t n, int delim);
#ifdef HAVE_W32_SYSTEM
@@ -54,15 +61,14 @@
#endif
-const char *ascii_memistr( const char *buf, size_t buflen, const char *sub );
int ascii_isupper (int c);
int ascii_islower (int c);
int ascii_toupper (int c);
int ascii_tolower (int c);
int ascii_strcasecmp( const char *a, const char *b );
int ascii_strncasecmp (const char *a, const char *b, size_t n);
-int ascii_memcasecmp( const char *a, const char *b, size_t n );
-const char *ascii_memistr ( const char *buf, size_t buflen, const char *sub);
+int ascii_memcasecmp( const void *a, const void *b, size_t n );
+const char *ascii_memistr ( const void *buf, size_t buflen, const char *sub);
void *ascii_memcasemem (const void *haystack, size_t nhaystack,
const void *needle, size_t nneedle);
Modified: trunk/jnlib/strlist.c
===================================================================
--- trunk/jnlib/strlist.c 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/strlist.c 2006-09-04 16:39:01 UTC (rev 234)
@@ -1,5 +1,5 @@
/* strlist.c - string helpers
- * Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 2000, 2001, 2006 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#include <config.h>
@@ -26,8 +27,10 @@
#include "libjnlib-config.h"
#include "strlist.h"
+#ifdef JNLIB_NEED_UTF8CONV
+#include "utf8conv.h"
+#endif
-
void
free_strlist( strlist_t sl )
{
@@ -53,26 +56,26 @@
return sl;
}
-#if 0
-/****************
- * same as add_to_strlist() but if is_utf8 is *not* set a conversion
- * to UTF8 is done
- */
+
+/* Same as add_to_strlist() but if is_utf8 is *not* set, a conversion
+ to UTF-8 is done. */
+#ifdef JNLIB_NEED_UTF8CONV
strlist_t
add_to_strlist2( strlist_t *list, const char *string, int is_utf8 )
{
- strlist_t sl;
-
- if( is_utf8 )
- sl = add_to_strlist( list, string );
- else {
- char *p = native_to_utf8( string );
- sl = add_to_strlist( list, p );
- m_free( p );
+ strlist_t sl;
+
+ if (is_utf8)
+ sl = add_to_strlist( list, string );
+ else
+ {
+ char *p = native_to_utf8( string );
+ sl = add_to_strlist( list, p );
+ jnlib_free ( p );
}
- return sl;
+ return sl;
}
-#endif
+#endif /* JNLIB_NEED_UTF8CONV*/
strlist_t
append_to_strlist( strlist_t *list, const char *string )
@@ -93,22 +96,24 @@
return sl;
}
-#if 0
+
+#ifdef JNLIB_NEED_UTF8CONV
strlist_t
append_to_strlist2( strlist_t *list, const char *string, int is_utf8 )
{
- strlist_t sl;
-
- if( is_utf8 )
- sl = append_to_strlist( list, string );
- else {
- char *p = native_to_utf8( string );
- sl = append_to_strlist( list, p );
- m_free( p );
+ strlist_t sl;
+
+ if( is_utf8 )
+ sl = append_to_strlist( list, string );
+ else
+ {
+ char *p = native_to_utf8 (string);
+ sl = append_to_strlist( list, p );
+ jnlib_free( p );
}
- return sl;
+ return sl;
}
-#endif
+#endif /* JNLIB_NEED_UTF8CONV */
/* Return a copy of LIST. */
Modified: trunk/jnlib/strlist.h
===================================================================
--- trunk/jnlib/strlist.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/strlist.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#ifndef LIBJNLIB_STRLIST_H
@@ -32,15 +33,14 @@
void free_strlist (strlist_t sl);
strlist_t add_to_strlist (strlist_t *list, const char *string);
-/*strlist_t add_to_strlist2( strlist_t *list,
- const char *string, int is_utf8);*/
+strlist_t add_to_strlist2( strlist_t *list, const char *string, int is_utf8);
strlist_t append_to_strlist (strlist_t *list, const char *string);
+strlist_t append_to_strlist2 (strlist_t *list, const char *string,
+ int is_utf8);
strlist_t strlist_copy (strlist_t list);
-/*strlist_t append_to_strlist2( strlist_t *list, const char *string,
- int is_utf8);*/
strlist_t strlist_prev (strlist_t head, strlist_t node);
strlist_t strlist_last (strlist_t node);
char * strlist_pop (strlist_t *list);
Modified: trunk/jnlib/types.h
===================================================================
--- trunk/jnlib/types.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/types.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#ifndef LIBJNLIB_TYPES_H
Modified: trunk/jnlib/utf8conv.c
===================================================================
--- trunk/jnlib/utf8conv.c 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/utf8conv.c 2006-09-04 16:39:01 UTC (rev 234)
@@ -16,7 +16,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#include <config.h>
@@ -136,16 +137,17 @@
* new allocated UTF8 string.
*/
char *
-native_to_utf8 (const char *string)
+native_to_utf8 (const char *orig_string)
{
- const byte *s;
+ const unsigned char *string = (const unsigned char *)orig_string;
+ const unsigned char *s;
char *buffer;
- byte *p;
+ unsigned char *p;
size_t length = 0;
if (no_translation)
{
- buffer = jnlib_xstrdup (string);
+ buffer = jnlib_xstrdup (orig_string);
}
else if (active_charset)
{
@@ -156,7 +158,7 @@
length += 2; /* we may need 3 bytes */
}
buffer = jnlib_xmalloc (length + 1);
- for (p = buffer, s = string; *s; s++)
+ for (p = (unsigned char *)buffer, s = string; *s; s++)
{
if ((*s & 0x80))
{
@@ -187,7 +189,7 @@
length++;
}
buffer = jnlib_xmalloc (length + 1);
- for (p = buffer, s = string; *s; s++)
+ for (p = (unsigned char *)buffer, s = string; *s; s++)
{
if (*s & 0x80)
{
@@ -212,11 +214,12 @@
{
int nleft;
int i;
- byte encbuf[8];
+ unsigned char encbuf[8];
int encidx;
const byte *s;
size_t n;
- byte *buffer = NULL, *p = NULL;
+ char *buffer = NULL;
+ char *p = NULL;
unsigned long val = 0;
size_t slen;
int resync = 0;
@@ -225,7 +228,8 @@
/* 2. pass (p!=NULL): create string */
for (;;)
{
- for (slen = length, nleft = encidx = 0, n = 0, s = string; slen;
+ for (slen = length, nleft = encidx = 0, n = 0,
+ s = (const unsigned char *)string; slen;
s++, slen--)
{
if (resync)
Modified: trunk/jnlib/utf8conv.h
===================================================================
--- trunk/jnlib/utf8conv.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/utf8conv.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#ifndef LIBJNLIB_UTF8CONF_H
Modified: trunk/jnlib/xmalloc.c
===================================================================
--- trunk/jnlib/xmalloc.c 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/xmalloc.c 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#include <config.h>
Modified: trunk/jnlib/xmalloc.h
===================================================================
--- trunk/jnlib/xmalloc.h 2006-09-04 14:57:42 UTC (rev 233)
+++ trunk/jnlib/xmalloc.h 2006-09-04 16:39:01 UTC (rev 234)
@@ -15,7 +15,8 @@
*
* 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#ifndef LIBJNLIB_XMALLOC_H
More information about the Gnupg-commits
mailing list