Index: trunk/src/sh_error.c
===================================================================
--- trunk/src/sh_error.c	(revision 583)
+++ trunk/src/sh_error.c	(revision 1)
@@ -20,17 +20,8 @@
 #include "config_xor.h"
 
-/* Required on Linux to get the correct strerror_r function. Also
- * for recursive mutexes (_XOPEN_SOURCE >= 500). Gives funny error
- * on Solaris 10/gcc ('c99' compiler required - huh? Isn't gcc 
- * good enough?).
- */
-#if !defined(__sun__) && !defined(__sun)
-#define _XOPEN_SOURCE 600
-#undef  _GNU_SOURCE
-#endif
-#include <string.h>
 #include <stdio.h>     
 #include <stdlib.h>     
 #include <stdarg.h>
+#include <string.h>
 #include <ctype.h>
 #include <limits.h>
@@ -59,8 +50,7 @@
 #include "sh_unix.h"
 #include "sh_tiger.h"
-#include "sh_nmail.h"
-#include "sh_xfer.h"
+#include "sh_mail.h"
+#include "sh_forward.h"
 #include "sh_prelude.h"
-#include "sh_pthread.h"
 
 #if defined(WITH_DATABASE)
@@ -77,6 +67,6 @@
 extern int clt_class;
 
-int flag_err_debug = S_FALSE;
-int flag_err_info  = S_FALSE;
+int flag_err_debug = SL_FALSE;
+int flag_err_info  = SL_FALSE;
 
 int  ShDFLevel[SH_ERR_T_END];
@@ -100,11 +90,11 @@
 static int  sh_error_init (void);
 
-inline
-static const char * get_format(unsigned long msg_id, int * priority, 
-			       unsigned int * class);
+/*@owned@*//*@null@*/inline
+static char * get_format(unsigned long msg_id, /*@out@*/int * priority, 
+			 /*@out@*/unsigned int * class);
 
 static int sh_error_string (struct _log_t * lmsg, va_list vl);
 
-extern int  sh_log_console (/*@null@*/const char *message);
+extern int  sh_log_console (/*@null@*/char *message);
 extern int  sh_log_syslog  (int  severity, /*@null@*/char *message);
 extern int  sh_log_file    (/*@null@*/char *message, 
@@ -112,5 +102,5 @@
 /* convert a string to a numeric priority
  */ 
-int sh_error_convert_level (const char * str_s);
+int sh_error_convert_level (char * str_s);
 
 static int  IsInitialized = BAD;
@@ -120,7 +110,4 @@
 int  OnlyStderr    = S_TRUE; 
 
-/* --- Enable facilities not safe for closeall(). --- 
- */
-int  enableUnsafe  = S_FALSE;
 
 /*********************************************
@@ -128,12 +115,11 @@
  *********************************************/
 
-int sh_error_verify (const char * s)
+int sh_error_verify (char * s)
 {
   char * foo;
-  char hashbuf[KEYBUF_SIZE];
 
   if (s[0] == '/')
     {
-      foo = sh_tiger_hash_gpg (s, TIGER_FILE, TIGER_NOLIM);
+      foo = sh_tiger_hash_gpg (s, TIGER_FILE, 0);
       fprintf (stdout, _("%s\n"),  foo);
       SH_FREE(foo);
@@ -143,7 +129,5 @@
       fprintf (stdout, _("string=<%s>, hash=<%s>\n"), 
 	       s, sh_tiger_hash (s, TIGER_DATA, 
-				 (unsigned long) sl_strlen(s), 
-				 hashbuf, sizeof(hashbuf))
-	       );
+				 (unsigned long) sl_strlen(s)));
     }
   (void) fflush(stdout);
@@ -164,62 +148,56 @@
 }
 
-void sh_error_enable_unsafe (int flag)
-{
-  enableUnsafe    = flag;
-  return;
-}
-
 static int dbg_store = 0;
 static int dbg_flag  = 0;
 
 static
-void compute_flag_err_debug(void)
+void compute_flag_err_debug()
 {
   if ((errFlags.loglevel & SH_ERR_ALL) != 0)
-    flag_err_debug = S_TRUE;
+    flag_err_debug = SL_TRUE;
   else if ((errFlags.printlevel & SH_ERR_ALL) != 0)
-    flag_err_debug = S_TRUE;
+    flag_err_debug = SL_TRUE;
   else if ((errFlags.maillevel & SH_ERR_ALL) != 0)
-    flag_err_debug = S_TRUE;
+    flag_err_debug = SL_TRUE;
   else if ((errFlags.exportlevel & SH_ERR_ALL) != 0)
-    flag_err_debug = S_TRUE;
+    flag_err_debug = SL_TRUE;
   else if ((errFlags.sysloglevel & SH_ERR_ALL) != 0)
-    flag_err_debug = S_TRUE;
+    flag_err_debug = SL_TRUE;
   else if ((errFlags.externallevel & SH_ERR_ALL) != 0)
-    flag_err_debug = S_TRUE;
+    flag_err_debug = SL_TRUE;
   else if ((errFlags.databaselevel & SH_ERR_ALL) != 0)
-    flag_err_debug = S_TRUE;
+    flag_err_debug = SL_TRUE;
   else if ((errFlags.preludelevel & SH_ERR_ALL) != 0)
-    flag_err_debug = S_TRUE;
+    flag_err_debug = SL_TRUE;
   else
-    flag_err_debug = S_FALSE;
+    flag_err_debug = SL_FALSE;
   return;
 }
 
 static
-void compute_flag_err_info(void)
+void compute_flag_err_info()
 {
   if ((errFlags.loglevel & SH_ERR_INFO) != 0)
-    flag_err_info = S_TRUE;
+    flag_err_info = SL_TRUE;
   else if ((errFlags.printlevel & SH_ERR_INFO) != 0)
-    flag_err_info = S_TRUE;
+    flag_err_info = SL_TRUE;
   else if ((errFlags.maillevel & SH_ERR_INFO) != 0)
-    flag_err_info = S_TRUE;
+    flag_err_info = SL_TRUE;
   else if ((errFlags.exportlevel & SH_ERR_INFO) != 0)
-    flag_err_info = S_TRUE;
+    flag_err_info = SL_TRUE;
   else if ((errFlags.sysloglevel & SH_ERR_INFO) != 0)
-    flag_err_info = S_TRUE;
+    flag_err_info = SL_TRUE;
   else if ((errFlags.externallevel & SH_ERR_INFO) != 0)
-    flag_err_info = S_TRUE;
+    flag_err_info = SL_TRUE;
   else if ((errFlags.databaselevel & SH_ERR_INFO) != 0)
-    flag_err_info = S_TRUE;
+    flag_err_info = SL_TRUE;
   else if ((errFlags.preludelevel & SH_ERR_INFO) != 0)
-    flag_err_info = S_TRUE;
+    flag_err_info = SL_TRUE;
   else
-    flag_err_info = S_FALSE;
+    flag_err_info = SL_FALSE;
   return;
 }
 
-void sh_error_dbg_switch(void)
+void sh_error_dbg_switch()
 {
   if (dbg_flag == 0)
@@ -230,5 +208,5 @@
 			     SH_ERR_SEVERE | SH_ERR_FATAL);
       dbg_flag  = 1;
-      flag_err_debug = S_TRUE;
+      flag_err_debug = SL_TRUE;
     }
   else {
@@ -241,16 +219,14 @@
 }
 
-static int sh_error_set_classmask (const char * str, int * facility_mask)
+static int sh_error_set_classmask (/*@notnull@*/char * c, int * facility_mask)
 {
   char * p;
-  char * q;
   int    num = 0;
   unsigned int    i;
   size_t len;
-  char * c;
 
   SL_ENTER(_("sh_error_set_classmask"));
   
-  if (str == NULL)
+  if (c == NULL)
     SL_RETURN( -1, _("sh_error_set_classmask"));
 
@@ -258,11 +234,7 @@
     (void) sh_error_init();
 
-  if (str[0] == (char) 34)
-    ++str;
-  len = strlen(str);
-
-  c = SH_ALLOC(len+1);
-  sl_strlcpy(c, str, len+1);
-
+  if (c[0] == (char) 34)
+    ++c;
+  len = strlen(c);
   if (c[len-1] == (char) 34)
     c[len-1] = '\0';
@@ -271,25 +243,14 @@
 
   do {
-#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_STRTOK_R)
-    char * saveptr;
-    if (num == 0) {
-      p = strtok_r (c, " ,\t", &saveptr);
-      ++num;
-    } else {
-      p = strtok_r (NULL, " ,\t", &saveptr);
-    }
-#else
-    if (num == 0) {
-      p = strtok (c, " ,\t");
-      ++num;
-    } else {
+    if (num == 0)
+      {
+	p = strtok (c, " ,\t");
+	++num;
+      }
+    else
       p = strtok (NULL, " ,\t");
-    }
-#endif
 
     if (p == NULL)
       break;
-
-    q = p; while (*q != '\0') { *q = toupper( (int) *q); ++q; }
 
     for (i = 0; i < SH_CLA_MAX; ++i)
@@ -312,37 +273,36 @@
   } while (p);
 
-  SH_FREE(c);
   SL_RETURN( 0, _("sh_error_set_classmask"));
 }
 
-int sh_error_log_mask (const char * c)
+int sh_error_log_mask (char * c)
 {
   return (sh_error_set_classmask(c, &(errFlags.log_class)));
 }
-int sh_error_mail_mask (const char * c)
+int sh_error_mail_mask (char * c)
 {
   return (sh_error_set_classmask(c, &(errFlags.mail_class)));
 }
-int sh_error_print_mask (const char * c)
+int sh_error_print_mask (char * c)
 {
   return (sh_error_set_classmask(c, &(errFlags.print_class)));
 }
-int sh_error_export_mask (const char * c)
+int sh_error_export_mask (char * c)
 {
   return (sh_error_set_classmask(c, &(errFlags.export_class)));
 }
-int sh_error_syslog_mask (const char * c)
+int sh_error_syslog_mask (char * c)
 {
   return (sh_error_set_classmask(c, &(errFlags.syslog_class)));
 }
-int sh_error_external_mask (const char * c)
+int sh_error_external_mask (char * c)
 {
   return (sh_error_set_classmask(c, &(errFlags.external_class)));
 }
-int sh_error_database_mask (const char * c)
+int sh_error_database_mask (char * c)
 {
   return (sh_error_set_classmask(c, &(errFlags.database_class)));
 }
-int sh_error_prelude_mask (const char * c)
+int sh_error_prelude_mask (char * c)
 {
   return (sh_error_set_classmask(c, &(errFlags.prelude_class)));
@@ -351,100 +311,92 @@
 
 
-char * sh_error_message (int tellme, char * str, size_t len)
-{
-
-#if defined(HAVE_STRERROR_R)
-  if (len > 0) str[0] = '\0';
-  strerror_r(tellme, str, len);
-  return str;
-#elif defined(HAVE_STRERROR)
-  sl_strlcpy(str, strerror(tellme), len);
-  return str;
+/*@owned@*/char * sh_error_message (int tellme)
+{
+
+#if defined(HAVE_STRERROR)
+  /*@i@*/return strerror(tellme);
 #else
 
-  char *p = NULL;
 #ifdef EACCES
-    if (tellme == EACCES)  p = _("Permission denied.");
+    if (tellme == EACCES)  return _("Permission denied.");
 #endif
 #ifdef EAGAIN
-    if (tellme == EAGAIN)  p = _("Try again.");
+    if (tellme == EAGAIN)  return _("Try again.");
 #endif
 #ifdef EBADF
-    if (tellme == EBADF)   p = _("File descriptor in bad state.");
+    if (tellme == EBADF)   return _("File descriptor in bad state.");
 #endif
 #ifdef EEXIST
-    if (tellme == EEXIST)  p = _("File exists.");
+    if (tellme == EEXIST)  return _("File exists.");
 #endif
 #ifdef EFAULT
-    if (tellme == EFAULT)  p = _("Bad address.");
+    if (tellme == EFAULT)  return _("Bad address.");
 #endif
 #ifdef EINVAL
-    if (tellme == EINVAL)  p = _("Invalid argument.");
+    if (tellme == EINVAL)  return _("Invalid argument.");
 #endif
 #ifdef EISDIR
-    if (tellme == EISDIR)  p = _("Is a directory.");
+    if (tellme == EISDIR)  return _("Is a directory.");
 #endif
 #ifdef EINTR
-    if (tellme == EINTR)   p = _("System call was interrupted.");
+    if (tellme == EINTR)   return _("System call was interrupted.");
 #endif
 #ifdef EIO
-    if (tellme == EIO)     p = _("Low-level I/O error.");
+    if (tellme == EIO)     return _("Low-level I/O error.");
 #endif
 #ifdef ELOOP
-    if (tellme == ELOOP)   p = _("Too many symbolic links encountered.");
+    if (tellme == ELOOP)   return _("Too many symbolic links encountered.");
 #endif
 #ifdef EMFILE
-    if (tellme == EMFILE)  p = _("Too many open files.");
+    if (tellme == EMFILE)  return _("Too many open files.");
 #endif
 #ifdef EMLINK
-    if (tellme == EMLINK)  p = _("Too many links.");
+    if (tellme == EMLINK)  return _("Too many links.");
 #endif
 #ifdef ENAMETOOLONG
     if (tellme == ENAMETOOLONG) 
-                           p = _("File name too long."); 
+                           return _("File name too long."); 
 #endif
 #ifdef ENFILE
-    if (tellme == ENFILE)  p = _("File table overflow.");
+    if (tellme == ENFILE)  return _("File table overflow.");
 #endif
 #ifdef ENOENT
-    if (tellme == ENOENT)  p = _("File does not exist.");
+    if (tellme == ENOENT)  return _("File does not exist.");
 #endif
 #ifdef ENOMEM
-    if (tellme == ENOMEM)  p = _("Out of memory.");
+    if (tellme == ENOMEM)  return _("Out of memory.");
 #endif
 #ifdef ENOSPC
-    if (tellme == ENOSPC)  p = _("No space on device.");
+    if (tellme == ENOSPC)  return _("No space on device.");
 #endif
 #ifdef ENOTDIR
-    if (tellme == ENOTDIR) p = _("Not a directory.");
+    if (tellme == ENOTDIR) return _("Not a directory.");
 #endif
 #ifdef ENOTSOCK
-    if (tellme == ENOTSOCK) p = _("Not a socket.");
+    if (tellme == ENOTSOCK) return _("Not a socket.");
 #endif
 #ifdef EOPNOTSUPP
-    if (tellme == EOPNOTSUPP) p = _("Socket is not of type SOCK_STREAM.");
+    if (tellme == EOPNOTSUPP) return _("Socket is not of type SOCK_STREAM.");
 #endif
 #ifdef EPERM
-    if (tellme == EPERM)   p = _("Permission denied.");
+    if (tellme == EPERM)   return _("Permission denied.");
 #endif
 #ifdef EPIPE
-    if (tellme == EPIPE)   p = _("No read on pipe.");
+    if (tellme == EPIPE)   return _("No read on pipe.");
 #endif
 #ifdef EROFS
-    if (tellme == EROFS)    p = _("Read-only file system.");
+    if (tellme == EROFS)    return _("Read-only file system.");
 #endif
 #ifdef ETXTBSY
-    if (tellme == ETXTBSY) p = _("Text file busy.");
+    if (tellme == ETXTBSY) return _("Text file busy.");
 #endif
 #ifdef EWOULDBLOCK
     if (tellme == EWOULDBLOCK) 
-      p = _("No connections on non-blocking socket.");
+      return _("No connections on non-blocking socket.");
 #endif
 #ifdef EXDEV
-    if (tellme == EXDEV)    p = _("Not on same file system.");
-#endif
-    if (!p) p = _("Unknown error");
-    sl_strlcpy(str, p, len);
-    return str;
+    if (tellme == EXDEV)    return _("Not on same file system.");
+#endif
+    return _("Unknown error");
 #endif /* ifndef HAVE_STRERROR */
 }
@@ -471,5 +423,5 @@
 typedef struct eef 
 {
-  const char * str;
+  char * str;
   int    val;
 } eef_struc;
@@ -494,10 +446,8 @@
 };
 
-int sh_error_convert_level (const char * str_s)
+int sh_error_convert_level (char * str_s)
 {
   int i;
   int level = (-1);
-  char * tmp;
-  char * q;
   
   SL_ENTER(_("sh_error_convert_level"));
@@ -506,10 +456,7 @@
      SL_RETURN( -1, _("sh_error_convert_level"));
 
-  q = sh_util_strdup(str_s);
-  tmp = q; while (*tmp != '\0') { *tmp = tolower( (int) *tmp); ++tmp; }
-  
   for (i = 0; i < SH_EEF_MAX; ++i)
     {
-      if (0 == sl_strncmp(q, _(eef_tab[i].str), 
+      if (0 == sl_strncmp(str_s, _(eef_tab[i].str), 
                           sl_strlen(eef_tab[i].str))) 
 	{
@@ -519,5 +466,4 @@
     }
 
-  SH_FREE(q);
   SL_RETURN( level, _("sh_error_convert_level"));
 }
@@ -526,5 +472,5 @@
 /* --- Set severity levels. ---
  */
-int sh_error_set_iv (int iv, const char *  str_s)
+int sh_error_set_iv (int iv, char *  str_s)
 {
   int level = (-1);
@@ -558,20 +504,13 @@
 }
 
-int sh_error_set_level(const char * str_in, int * facility)
+int sh_error_set_level(char * str_in, int * facility)
 {
   register int  i, j, f = BAD;
 
   int  old_facility;
-  char * str_s;
-  char * str_orig;
-  char * tmp;
+  char * str_s = str_in;
 
   SL_ENTER(_("sh_error_set_level"));
 
-  str_s = sh_util_strdup(str_in);
-  str_orig = str_s;
-  
-  tmp = str_s; while (*tmp != '\0') { *tmp = tolower( (int) *tmp); ++tmp; }
-  
   if (IsInitialized == BAD) 
     (void) sh_error_init();
@@ -664,9 +603,4 @@
     }
 
-  if (!str_s)
-    {
-      if (str_orig) SH_FREE(str_orig);
-      SL_RETURN ((-1), _("sh_error_set_level"));
-    }
   /* skip to end of string
    */
@@ -692,17 +626,15 @@
       sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_EINVALS, 
 		       _("priority"), str_in);
-      SH_FREE(str_orig);
       SL_RETURN (-1, _("sh_error_set_level"));
     }
   compute_flag_err_debug();
   compute_flag_err_info();
-  SH_FREE(str_orig);
   SL_RETURN (0, _("sh_error_set_level"));
 }
 
-#if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER)
+#ifdef SH_WITH_CLIENT
 /* set severity for TCP export
  */
-int sh_error_setexport(const char *  str_s)
+int sh_error_setexport(char *  str_s)
 {
   static int reject = 0;
@@ -721,5 +653,5 @@
 extern void dlog_set_active(int flag);
 
-int sh_error_setprint(const char *  str_s)
+int sh_error_setprint(char *  str_s)
 {
   static int reject = 0;
@@ -744,5 +676,5 @@
 /* set level for error logging
  */
-int sh_error_setlog(const char * str_s)
+int sh_error_setlog(char * str_s)
 {
   static int reject = 0;
@@ -759,5 +691,5 @@
 /* set severity for syslog
  */
-int sh_error_set_syslog (const char * str_s)
+int sh_error_set_syslog (char * str_s)
 {
   static int reject = 0;
@@ -774,5 +706,5 @@
 /* set severity for external
  */
-int sh_error_set_external (const char * str_s)
+int sh_error_set_external (char * str_s)
 {
   static int reject = 0;
@@ -790,5 +722,5 @@
 /* set severity for database
  */
-int sh_error_set_database (const char * str_s)
+int sh_error_set_database (char * str_s)
 {
   static int reject = 0;
@@ -806,5 +738,5 @@
 /* set severity for prelude
  */
-int sh_error_set_prelude (const char * str_s)
+int sh_error_set_prelude (char * str_s)
 {
   static int reject = 0;
@@ -822,7 +754,7 @@
 /* init or re-init log facilities that need it
  */
-void sh_error_fixup(void)
-{
-#if defined(HAVE_LIBPRELUDE)
+void sh_error_fixup()
+{
+#if defined(HAVE_LIBPRELUDE_9)
   if ((errFlags.preludelevel & SH_ERR_NOT)   == 0)
     sh_prelude_init();
@@ -838,7 +770,7 @@
 /* to be called from sh_prelude_reset
  */
-void sh_error_init_prelude(void)
-{
-#if defined(HAVE_LIBPRELUDE)
+void sh_error_init_prelude()
+{
+#if defined(HAVE_LIBPRELUDE_9)
   if ((errFlags.preludelevel & SH_ERR_NOT)   == 0)
     sh_prelude_init();
@@ -852,5 +784,5 @@
 /* set severity for mailing
  */
-int sh_error_setseverity (const char * str_s)
+int sh_error_setseverity (char * str_s)
 {
   static int reject = 0;
@@ -866,70 +798,14 @@
 #ifdef SH_WITH_SERVER
 static char inet_peer[SH_MINIBUF] = { '\0' };
-#ifdef HAVE_LIBPRELUDE
-static char inet_peer_ip[SH_IP_BUF] = { '\0' };
-
-void sh_error_set_peer_ip(const char * str)
+
+void sh_error_set_peer(const char * str)
 {
   if (str == NULL)
-    inet_peer_ip[0] = '\0';
+    memset(inet_peer, '\0', SH_MINIBUF);
   else
-    sl_strlcpy(inet_peer_ip, str, sizeof(inet_peer_ip));
-}
-#endif
-
-void sh_error_set_peer(const char * str)
-{
-  if (str == NULL)
-    inet_peer[0] = '\0';
-  else
-    sl_strlcpy(inet_peer, str, sizeof(inet_peer));
-}
-#endif
-
-#if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
-#include "sh_checksum.h"
-static char * sh_error_replace(const char * msg)
-{
-  char * ret   = NULL;
-
-  if (sh_tiger_get_hashtype () == SH_SHA256)
-    {
-      char * store = NULL;
-
-#ifdef SH_USE_XML
-      char c_end  = '"';
-      char * str  = _("chksum_old=\"");
-      char * str2 = _("chksum_new=\"");
-#else
-      char c_end  = '>';
-      char * str  = _("chksum_old=<");
-      char * str2 = _("chksum_new=<");
-#endif
-
-      ret = SHA256_ReplaceBaseByHex(msg, str, c_end);
-
-      if (ret) {
-	store = ret;
-	ret   = SHA256_ReplaceBaseByHex(ret, str2, c_end);
-	if (ret)
-	  SH_FREE(store);
-	else
-	  ret = store;
-      } else {
-	ret   = SHA256_ReplaceBaseByHex(msg, str2, c_end);
-      }
-    }
-  return ret;
-}
-static void sh_replace_free(char * msg)
-{
-  if (msg)
-    SH_FREE(msg);
-  return;
-}
-#else
-static char * sh_error_replace(const char * msg) { (void) msg; return NULL; }
-static void sh_replace_free(char * msg) { (void) msg; return; }
-#endif
+    sl_strlcpy(inet_peer, str, SH_MINIBUF);
+}
+#endif
+  
 
 /**********************************************************
@@ -944,7 +820,5 @@
  **********************************************************/
 
-SH_MUTEX_RECURSIVE(mutex_err_handle);
-
-void sh_error_handle (int sev1, const char * file, long line, 
+void sh_error_handle (int sev, char * file, long line, 
 		      long status, unsigned long msg_id, ...)
 {
@@ -954,18 +828,14 @@
   int    severity;
   unsigned int class;
-  const char * fmt;
-  volatile int sev = sev1;            /* Avoids the 'clobbered by longjmp' warning. */
-
-  int    flag_inet;
+  char * fmt;
+
+  int    flag_inet  = S_FALSE;
+  int    class_inet = clt_class;      /* initialize from global */
 
 #ifdef SH_WITH_SERVER
-  int    class_inet = clt_class;      /* initialize from global */
   char   local_inet_peer[SH_MINIBUF];
-#ifdef HAVE_LIBPRELUDE
-  char   local_inet_peer_ip[SH_IP_BUF];
-#endif    
-#endif
-
-#if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER)
+#endif
+
+#ifdef SH_WITH_CLIENT
   char   * ex_msg;
 #endif
@@ -973,6 +843,4 @@
   char   * escape_msg;
 #endif
-
-  char   * hexmsg = NULL;
 
   static int    own_block = 0;
@@ -988,5 +856,5 @@
   static int syslog_block = 0;
   static int log_block    = 0;
-#if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER)
+#if defined(SH_WITH_CLIENT)
   static int export_block = 0;
 #endif
@@ -1003,7 +871,4 @@
   SL_ENTER(_("sh_error_handle"));
 
-  SH_MUTEX_RECURSIVE_INIT(mutex_err_handle);
-  SH_MUTEX_RECURSIVE_LOCK(mutex_err_handle);
-
 #ifdef SH_WITH_SERVER
   /* copy the global string into a local array
@@ -1011,45 +876,34 @@
   if ((msg_id == MSG_TCP_MSG) && (inet_peer[0] != '\0'))
     {
-      sl_strlcpy(local_inet_peer, inet_peer, sizeof(local_inet_peer));
+      sl_strlcpy(local_inet_peer, inet_peer, SH_MINIBUF);
       sh_error_set_peer(NULL);
     }
   else
     local_inet_peer[0] = '\0';
-
-#ifdef HAVE_LIBPRELUDE
-  if ((msg_id == MSG_TCP_MSG) && (inet_peer_ip[0] != '\0'))
-    {
-      sl_strlcpy(local_inet_peer_ip, inet_peer_ip, sizeof(local_inet_peer_ip));
-      sh_error_set_peer_ip(NULL);
-    }
-  else
-    local_inet_peer_ip[0] = '\0';
 #endif
 
   clt_class = (-1);      /* reset global */
-#endif
-
 
   if (own_block == 1)
     {
-      goto exit_here;
+      SL_RET0(_("sh_error_handle"));
     }
 
   /* --- Initialize to default values. ---
    */
+  own_block = 1;
   if (IsInitialized == BAD) 
     (void) sh_error_init();
-
-  /* Returns pointer to (constant|thread-specific) static memory
-   */
+  own_block = 0;
+
+  /* --- Consistency checks. ---
+   */
+  own_block = 1;
   fmt = /*@i@*/get_format (msg_id, &severity, &class);
-
-#ifdef SH_WITH_SERVER
+  own_block = 0;
+
   if (class_inet != (-1))
     class = (unsigned int) class_inet;
-#endif
-
-  /* --- Consistency check. ---
-   */
+
   ASSERT((fmt != NULL), _("fmt != NULL"))
   if (fmt == NULL)
@@ -1058,5 +912,5 @@
 	      _("ERROR: msg=<NULL format>, file=<%s>, line=<%ld>\n"), 
 	      file, line);
-      goto exit_here;
+      SL_RET0(_("sh_error_handle"));
     }
 
@@ -1066,23 +920,7 @@
     severity = sev;
 
-  /* --- Some statistics. ---
-   */
-#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
-  if ( ((1 << class) & ERROR_CLA) && 
-       (severity & (SH_ERR_ERR|SH_ERR_SEVERE|SH_ERR_FATAL)))
-    {
-      ++sh.statistics.files_error;
-    }
-#endif
-
-  /* these are messages from remote sources
-   */
   if ((severity  & SH_ERR_INET) != 0)
     {
       flag_inet = S_TRUE;
-    }
-  else
-    {
-      flag_inet  = S_FALSE;
     }
 
@@ -1095,5 +933,5 @@
        ( (errFlags.sysloglevel  & severity    ) == 0 || 
 	 (errFlags.syslog_class & (1 << class)) == 0 )     &&
-#if defined(SH_WITH_CLIENT) || defined(SH_WITH_CLIENT)
+#ifdef SH_WITH_CLIENT
        ( (errFlags.exportlevel  & severity    ) == 0 ||
 	 (errFlags.export_class & (1 << class)) == 0 )     &&
@@ -1114,23 +952,16 @@
 	 (errFlags.mail_class    & (1 << class)) == 0 )
 #ifdef SH_WITH_SERVER
-       && (flag_inet == S_FALSE) /* still log messages from remote sources */
+      && (flag_inet == S_FALSE)
 #endif
        )
     {
-      goto exit_here;
+      SL_RET0(_("sh_error_handle"));
     }
 
   if ((severity & SH_ERR_NOT) != 0)
     {
-      goto exit_here;
-    }
-  
-#if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
-  if ((sh_global_check_silent > SH_SILENT_STD) &&
-      (((1 << FIL) & (1 << class)) != 0))
-    {
-      goto exit_here;
-    }
-#endif
+      SL_RET0(_("sh_error_handle"));
+    }
+
 
   /* Allocate space for the message.
@@ -1147,8 +978,11 @@
   lmsg->line     = line;
   lmsg->status   = status;
+  own_block = 0;
+
 
   /* Format the log message with timestamp etc.
    * Allocate lmsg->msg
    */
+  own_block = 1;
   va_start (vl, msg_id);
   (void) sh_error_string (lmsg, vl);
@@ -1156,5 +990,4 @@
   own_block = 0;
 
-  hexmsg = sh_error_replace(lmsg->msg);
 
   /* Log to stderr.
@@ -1177,5 +1010,5 @@
 	   *  Reports first error after failure. Always tries.
 	   */
-	  (void) sh_log_console (hexmsg ? hexmsg : lmsg->msg);
+	  (void) sh_log_console (lmsg->msg);
 	  print_block = 0;
 	}
@@ -1185,5 +1018,5 @@
   /* Full logging enabled.
    */
-  if (OnlyStderr == S_FALSE)  /* full error logging enabled */
+  if (OnlyStderr == BAD)  /* full error logging enabled */
     {
 
@@ -1205,5 +1038,5 @@
 	       * Ignores errors. Always tries.
 	       */
-	      (void) sh_log_syslog (lmsg->severity, hexmsg ? hexmsg : lmsg->msg);
+	      (void) sh_log_syslog (lmsg->severity, lmsg->msg);
 	      syslog_block = 0;
 	    }
@@ -1227,5 +1060,5 @@
 	       *  Reports first error after failure. Always tries.
 	       */
-	      (void) sh_ext_execute ('l', 'o', 'g', hexmsg ? hexmsg : lmsg->msg, 0);
+	      (void) sh_ext_execute ('l', 'o', 'g', lmsg->msg, 0);
 	      external_block = 0;
 	    }
@@ -1242,5 +1075,5 @@
 	  class != AUD)
 	{
-	  if (database_block == 0 && enableUnsafe == S_TRUE)
+	  if (database_block == 0)
 	    {
 	      /* truncates; query_max is 16k
@@ -1280,37 +1113,27 @@
        * to log server
        ****************************************************/
-#if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER)
+#ifdef SH_WITH_CLIENT
       /* Export by TCP.
        */
-
-      if ( ((errFlags.exportlevel  & severity  )   != 0 &&
-	    (errFlags.export_class & (1 << class)) != 0 &&
-	    (errFlags.exportlevel  & SH_ERR_NOT)   == 0 &&
-	    class != AUD                               )
-#ifdef SH_WITH_SERVER
-	   /* always log inet to export */
-	   || (flag_inet == S_TRUE && sh.srvexport.name[0] != '\0') 
-#endif
-          /* sh.flag.isserver != GOOD                    && */
-          /* (flag_inet == S_FALSE) */ /* don't log inet to export */
-	   )
+      if ((errFlags.exportlevel  & severity  )   != 0 &&
+          (errFlags.export_class & (1 << class)) != 0 &&
+          (errFlags.exportlevel  & SH_ERR_NOT)   == 0 &&
+	  class != AUD                                &&
+          sh.flag.isserver != GOOD                    &&
+          (flag_inet == S_FALSE) ) /* don't log inet to export */
         {
           if (export_block == 0)
             {
 	      int retval;
-	      size_t ex_len;
 
 	      /* will truncate to 65280 bytes 
 	       */
               export_block = 1;
-	      /* ex_len = 64 + sl_strlen(lmsg->msg) + 1; */
-	      ex_len = sl_strlen(lmsg->msg);
-	      if (sl_ok_adds(ex_len, 65))
-		ex_len = 64 + ex_len + 1;
-	      ex_msg = SH_ALLOC (ex_len);
-
-	      sl_snprintf(ex_msg, ex_len, _("%d?%u?%s"),
-		      severity, class, lmsg->msg);
-              retval = sh_xfer_report (ex_msg);
+	      ex_msg = SH_ALLOC (64 + sl_strlen(lmsg->msg) + 1);
+	      /*@-bufferoverflowhigh@*/
+	      sprintf(ex_msg, _("%d?%u?%s"),             /* known to fit  */
+			   severity, class, lmsg->msg);
+	      /*@-bufferoverflowhigh@*/
+              retval = sh_forward (ex_msg);
 	      SH_FREE(ex_msg);
               export_block = 0;
@@ -1342,9 +1165,9 @@
 	      mail_block = 1;
 
-	      BREAKEXIT(sh_nmail_msg);
+	      BREAKEXIT(sh_mail_msg);
 	      if ( (severity & SH_ERR_FATAL) == 0) 
-		retval = sh_nmail_pushstack (severity, hexmsg ? hexmsg : lmsg->msg, NULL);
+		retval = sh_mail_pushstack (lmsg->msg);
 	      else 
-		retval = sh_nmail_msg (severity, hexmsg ? hexmsg : lmsg->msg, NULL);
+		retval = sh_mail_msg (lmsg->msg);
 
 	      mail_block = 0;
@@ -1368,5 +1191,5 @@
 	  )
 	{
-	  if (prelude_block == 0 && enableUnsafe == S_TRUE)
+	  if (prelude_block == 0)
 	    {
 	      /* will truncate to 998 bytes 
@@ -1378,13 +1201,7 @@
 	       *  Reports first error after failure. Always tries.
 	       */
-#if defined(HAVE_LIBPRELUDE) && defined(SH_WITH_SERVER) 
-	      (void) sh_prelude_alert (severity, (int) class, 
-				       hexmsg ? hexmsg : lmsg->msg, lmsg->status, msg_id, 
-				       local_inet_peer_ip);
-#else
-	      (void) sh_prelude_alert (severity, (int) class, 
-				       hexmsg ? hexmsg : lmsg->msg, lmsg->status, msg_id, 
-				       NULL);
-#endif
+	      (void) sh_prelude_alert (severity, (int) class, lmsg->msg,
+				       lmsg->status, msg_id);
+
 	      prelude_block = 0;
 	    }
@@ -1422,8 +1239,8 @@
 		    (void) sh_log_file (lmsg->msg, NULL);
 		  else
-                    (void) sh_log_file (lmsg->msg, local_inet_peer);
+		    (void) sh_log_file (lmsg->msg, local_inet_peer);
 		}
 #else
-              (void) sh_log_file (hexmsg ? hexmsg : lmsg->msg, NULL);
+              (void) sh_log_file (lmsg->msg, NULL);
 #endif
 	      /* sh_log_file (lmsg->msg); */
@@ -1440,95 +1257,13 @@
   if (lmsg->msg)
     SH_FREE( lmsg->msg );
-  sh_replace_free(hexmsg);
-
-  memset ( lmsg, 0, sizeof(struct _log_t) );
+
+  memset ( lmsg, (int) '\0', sizeof(struct _log_t) );
   MUNLOCK( (char *) lmsg,       sizeof(struct _log_t) );
   SH_FREE( lmsg );
   own_block = 0;
 
- exit_here:
-  ; /* label at end of compound statement */
-  SH_MUTEX_RECURSIVE_UNLOCK(mutex_err_handle);
-
   /*@i@*/SL_RET0(_("sh_error_handle"));
 /*@i@*/}
 
-#if defined(SH_WITH_MAIL)
-void sh_error_mail (const char * alias, int sev, 
-		    const char * file, long line, 
-		    long status, unsigned long msg_id, ...)
-{
-  va_list         vl;                 /* argument list          */
-  struct _log_t * lmsg;
-
-  int    severity;
-  unsigned int class;
-  const char * fmt;
-  int retval; 
-
-  SL_ENTER(_("sh_error_mail"));
-
-  /* Returns pointer to (constant|thread-specific) static memory
-   */
-  fmt = /*@i@*/get_format (msg_id, &severity, &class);
-
-  if (!fmt)
-    {
-      SL_RET0(_("sh_error_mail"));
-    }
-
-  /* --- Override the catalogue severity. ---
-   */
-  if (sev != (-1))
-    severity = sev;
-
-  /* --- Build the message. ---
-   */
-  lmsg = (struct _log_t *) SH_ALLOC(sizeof(struct _log_t));
-  MLOCK( (char *) lmsg, sizeof(struct _log_t));
-  /*@i@*/lmsg->msg = NULL;
-
-  /*@i@*/(void) sl_strlcpy(lmsg->format, fmt, SH_PATHBUF);
-  (void) sl_strlcpy(lmsg->file, file, SH_PATHBUF);
-  lmsg->severity = severity;
-  lmsg->class    = (int) class;
-  lmsg->line     = line;
-  lmsg->status   = status;
-
-  /* Format the log message with timestamp etc.
-   * Allocate lmsg->msg
-   */
-  va_start (vl, msg_id);
-  (void) sh_error_string (lmsg, vl);
-  va_end (vl);
-
-  if ( (severity & SH_ERR_FATAL) == 0) 
-    retval = sh_nmail_pushstack (severity, lmsg->msg, alias);
-  else 
-    retval = sh_nmail_msg (severity, lmsg->msg, alias);
-  
-  if (retval == -2)
-    {
-      sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_QUEUE_FULL,
-		       _("email"));
-    }
-  SL_RET0(_("sh_error_mail"));
-}
-#else
-void sh_error_mail (const char * alias, int sev, 
-		    const char * file, long line, 
-		    long status, unsigned long msg_id, ...)
-{
-  (void) alias;
-  (void) sev;
-  (void) file;
-  (void) line;
-  (void) status;
-  (void) msg_id;
-
-  return;
-}
-/* defined(SH_WITH_MAIL) */
-#endif 
 
 /* -------------------------  
@@ -1543,5 +1278,5 @@
  */
 /*@owned@*/ /*@null@*/inline
-static const char * get_format(unsigned long msg_id, /*@out@*/ int * priority, 
+static char * get_format(unsigned long msg_id, /*@out@*/ int * priority, 
 			 /*@out@*/unsigned int * class)
 {
@@ -1558,5 +1293,5 @@
 	  *priority = (int) msg_cat[i].priority;
 	  *class    = (unsigned int) msg_cat[i].class;
-	  SL_RETURN (((const char *) _(msg_cat[i].format)), _("get_format"));
+	  SL_RETURN (_(msg_cat[i].format), _("get_format"));
 	}
       ++i;
@@ -1571,8 +1306,8 @@
 /* allocate space for user-defined message header
  */
-int sh_error_ehead (/*@null@*/const char * str_s)
+int sh_error_ehead (/*@null@*/char * str_s)
 {
   size_t size;
-  const char * s;
+  char * s;
 
   SL_ENTER(_("sh_error_ehead"));
@@ -1589,5 +1324,5 @@
   
   size = /*@i@*/strlen(s);
-  if (/*@i@*/s[size-1] == (char) 34) --size; /* truncate */
+  if (/*@i@*/s[size-1] == (char) 34) --size;
 
   if (ehead_format != NULL)
@@ -1706,5 +1441,5 @@
   }
 
-  (void) sh_unix_time (0, tst, 64);
+  (void) sl_strlcpy (tst, sh_unix_time (0), 64);
   line = (unsigned long) lmsg->line;
   (void) sl_strlcpy (cla, _(class_cat[lmsg->class]), 11);
@@ -1747,10 +1482,6 @@
       len      = sl_strlen(lmsg->msg);
       /*@i@*/required = sl_vsnprintf(&(lmsg->msg[len]), 
-				     (lmsg->msg_len - len), lmsg->format, vl);
-
-      if ((required >= 0) && 
-	  sl_ok_adds(required, len) &&
-	  sl_ok_adds((required+len), 4) &&
-	  ((required + len) > (lmsg->msg_len - 4)) )
+			      (lmsg->msg_len - len), lmsg->format, vl);
+      if ( (required + len) > (lmsg->msg_len - 4) )
 	{
 	  /*@i@*/p = SH_ALLOC(required + len + 4);
@@ -1760,5 +1491,5 @@
 	  lmsg->msg_len = required + len + 4;
 	  (void) sl_vsnprintf(&(lmsg->msg[len]), 
-			      (required + 1), lmsg->format, vl2);
+			      (required + len + 1), lmsg->format, vl2);
 	}
       va_end(vl2);
@@ -1805,13 +1536,7 @@
 			     SH_ERR_STAMP | SH_ERR_ERR    | SH_ERR_SEVERE |
 			     SH_ERR_FATAL);
-  flag_err_info           = S_TRUE;
-#endif
-
-#if defined(SH_WITH_SERVER)
-  errFlags.exportlevel    = SH_ERR_NOT;
-#else
+#endif
   errFlags.exportlevel    = (SH_ERR_STAMP | SH_ERR_ERR    | SH_ERR_SEVERE |
 			     SH_ERR_FATAL);
-#endif
 
   errFlags.log_class      = 0xFFFF;
