- Don't claim HTTP/1.1 compliance.
[privoxy.git] / errlog.c
index 99ec173..d424381 100644 (file)
--- a/errlog.c
+++ b/errlog.c
@@ -1,4 +1,4 @@
-const char errlog_rcs[] = "$Id: errlog.c,v 1.47 2006/11/28 15:25:15 fabiankeil Exp $";
+const char errlog_rcs[] = "$Id: errlog.c,v 1.52 2007/07/14 07:28:47 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/errlog.c,v $
@@ -33,6 +33,25 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.47 2006/11/28 15:25:15 fabiankeil E
  *
  * Revisions   :
  *    $Log: errlog.c,v $
+ *    Revision 1.52  2007/07/14 07:28:47  fabiankeil
+ *    Add translation function for JB_ERR_FOO codes.
+ *
+ *    Revision 1.51  2007/05/11 11:51:34  fabiankeil
+ *    Fix a type mismatch warning.
+ *
+ *    Revision 1.50  2007/04/11 10:55:44  fabiankeil
+ *    Enforce some assertions that could be triggered
+ *    on mingw32 and other systems where we use threads
+ *    but no locks.
+ *
+ *    Revision 1.49  2007/04/08 16:44:15  fabiankeil
+ *    We need <sys/time.h> for gettimeofday(), not <time.h>.
+ *
+ *    Revision 1.48  2007/03/31 13:33:28  fabiankeil
+ *    Add alternative log_error() with timestamps
+ *    that contain milliseconds and without using
+ *    strcpy(), strcat() or sprintf().
+ *
  *    Revision 1.47  2006/11/28 15:25:15  fabiankeil
  *    Only unlink the pidfile if it's actually used.
  *
@@ -273,7 +292,8 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.47 2006/11/28 15:25:15 fabiankeil E
 
 #if defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY)
 #define USE_NEW_LOG_ERROR
-#include <time.h>
+/* For gettimeofday() */
+#include <sys/time.h>
 #endif /* defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY) */
 
 #if !defined(_WIN32) && !defined(__OS2__)
@@ -332,19 +352,19 @@ static char *os2_socket_strerr(int errcode, char *tmp_buf);
 #endif
 
 #ifdef FEATURE_PTHREAD
-static inline void lock_logfile()
+static inline void lock_logfile(void)
 {
    pthread_mutex_lock(&log_mutex);
 }
-static inline void unlock_logfile()
+static inline void unlock_logfile(void)
 {
    pthread_mutex_unlock(&log_mutex);
 }
-static inline void lock_loginit()
+static inline void lock_loginit(void)
 {
    pthread_mutex_lock(&log_init_mutex);
 }
-static inline void unlock_loginit()
+static inline void unlock_loginit(void)
 {
    pthread_mutex_unlock(&log_init_mutex);
 }
@@ -489,7 +509,7 @@ void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
  * Returns     :  thread_id
  *
  *********************************************************************/
-long get_thread_id(void)
+static long get_thread_id(void)
 {
    long this_thread = 1;  /* was: pthread_t this_thread;*/
 
@@ -659,7 +679,7 @@ static inline size_t get_clf_timestamp(char *buffer, size_t buffer_size)
  * Returns     :  Log level string.
  *
  *********************************************************************/
-inline const char *get_log_level_string(int loglevel)
+static inline const char *get_log_level_string(int loglevel)
 {
    char *log_level_string = NULL;
 
@@ -797,8 +817,8 @@ void log_error(int loglevel, const char *fmt, ...)
    outbuf = outbuf_save;
 
    /*
-    * Memsetting the whole buffer to zero
-    * here make things easier later on.
+    * Memsetting the whole buffer to zero (in theory)
+    * makes things easier later on.
     */
    memset(outbuf, 0, log_buffer_size);
 
@@ -827,10 +847,15 @@ void log_error(int loglevel, const char *fmt, ...)
       if (ch != '%')
       {
          outbuf[length++] = ch;
-         assert(outbuf[length] == '\0');
+         /*
+          * XXX: Only necessary on platforms which don't use pthread
+          * mutexes (mingw32 for example), where multiple threads can
+          * write to the buffer at the same time.
+          */
+         outbuf[length] = '\0';
          continue;
       }
-      assert(outbuf[length] == '\0');
+      outbuf[length] = '\0';
       ch = *src++;
       switch (ch) {
          case '%':
@@ -998,8 +1023,8 @@ void log_error(int loglevel, const char *fmt, ...)
       assert(outbuf[log_buffer_size] == '\0');
 
       snprintf(outbuf, log_buffer_size,
-         "%s Privoxy(%08lx) Fatal error: log_error()'s sanity checks failed. length: %u\n"
-         "Exiting.", timestamp, thread_id, length);
+         "%s Privoxy(%08lx) Fatal error: log_error()'s sanity checks failed. length: %d\n"
+         "Exiting.", timestamp, thread_id, (int)length);
       loglevel = LOG_LEVEL_FATAL;
    }
 
@@ -1488,6 +1513,48 @@ void log_error(int loglevel, const char *fmt, ...)
 #endif /* defined(USE_NEW_LOG_ERROR) */
 
 
+/*********************************************************************
+ *
+ * Function    :  jb_err_to_string
+ *
+ * Description :  Translates JB_ERR_FOO codes into strings.
+ *
+ *                XXX: the type of error codes is jb_err
+ *                but the typedef'inition is currently not
+ *                visible to all files that include errlog.h.
+ *
+ * Parameters  :
+ *          1  :  error = a valid jb_err code
+ *
+ * Returns     :  A string with the jb_err translation
+ *
+ *********************************************************************/
+const char *jb_err_to_string(int error)
+{
+   switch (error)
+   {
+      case JB_ERR_OK:
+         return "Success, no error";
+      case JB_ERR_MEMORY:
+         return "Out of memory";
+      case JB_ERR_CGI_PARAMS:
+         return "Missing or corrupt CGI parameters";
+      case JB_ERR_FILE:
+         return "Error opening, reading or writing a file";
+      case JB_ERR_PARSE:
+         return "Parse error";
+      case JB_ERR_MODIFIED:
+         return "File has been modified outside of the CGI actions editor.";
+      case JB_ERR_COMPRESS:
+         return "(De)compression failure";
+      default:
+         assert(0);
+         return "Unknown error";
+   }
+   assert(0);
+   return "Internal error";
+}
+
 #ifdef _WIN32
 /*********************************************************************
  *