-const char errlog_rcs[] = "$Id: errlog.c,v 1.127 2016/12/24 16:00:49 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
* printf-like fashion.
*
* Copyright : Written by and Copyright (C) 2001-2014 the
- * Privoxy team. http://www.privoxy.org/
+ * Privoxy team. https://www.privoxy.org/
*
* Based on the Internet Junkbuster originally written
* by and Copyright (C) 1997 Anonymous Coders and
#include "jbsockets.h"
#endif
-const char errlog_h_rcs[] = ERRLOG_H_VERSION;
-
-
/*
* LOG_LEVEL_FATAL cannot be turned off. (There are
* some exceptional situations where we need to get a
case LOG_LEVEL_FATAL:
log_level_string = "Fatal error";
break;
- case LOG_LEVEL_GPC:
+ case LOG_LEVEL_REQUEST:
log_level_string = "Request";
break;
case LOG_LEVEL_CONNECT:
void log_error(int loglevel, const char *fmt, ...)
{
va_list ap;
- char *outbuf = NULL;
- static char *outbuf_save = NULL;
+ char outbuf[LOG_BUFFER_SIZE+1];
char tempbuf[LOG_BUFFER_SIZE];
size_t length = 0;
const char * src = fmt;
long thread_id;
char timestamp[30];
- /*
- * XXX: Make this a config option,
- * why else do we allocate instead of using
- * an array?
- */
const size_t log_buffer_size = LOG_BUFFER_SIZE;
#if defined(_WIN32) && !defined(_WIN_CONSOLE)
* the taskbar icon animate. (There is an option to disable
* this but checking that is handled inside LogShowActivity()).
*/
- if ((loglevel == LOG_LEVEL_GPC) || (loglevel == LOG_LEVEL_CRUNCH))
+ if ((loglevel == LOG_LEVEL_REQUEST) || (loglevel == LOG_LEVEL_CRUNCH))
{
LogShowActivity();
}
thread_id = get_thread_id();
get_log_timestamp(timestamp, sizeof(timestamp));
- /* protect the whole function because of the static buffer (outbuf) */
- lock_logfile();
-
- if (NULL == outbuf_save)
- {
- outbuf_save = zalloc_or_die(log_buffer_size + 1); /* +1 for paranoia */
- }
- outbuf = outbuf_save;
-
/*
* Memsetting the whole buffer to zero (in theory)
* makes things easier later on.
*/
- memset(outbuf, 0, log_buffer_size);
+ memset(outbuf, 0, sizeof(outbuf));
/* Add prefix for everything but Common Log Format messages */
if (loglevel != LOG_LEVEL_CLF)
break;
case 'c':
/*
- * Note that char paramaters are converted to int, so we need to
+ * Note that char parameters are converted to int, so we need to
* pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
*/
tempbuf[0] = (char) va_arg(ap, int);
assert(NULL != logfp);
#endif
+ lock_logfile();
+
if (loglevel == LOG_LEVEL_FATAL)
{
- fatal_error(outbuf_save);
+ fatal_error(outbuf);
/* Never get here */
}
if (logfp != NULL)
{
- fputs(outbuf_save, logfp);
+ fputs(outbuf, logfp);
}
#if defined(_WIN32) && !defined(_WIN_CONSOLE)
/* Write to display */
- LogPutString(outbuf_save);
+ LogPutString(outbuf);
#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
unlock_logfile();
*
* 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 : jb_error = a valid jb_err code
*
* Returns : A string with the jb_err translation
*
*********************************************************************/
-const char *jb_err_to_string(int jb_error)
+const char *jb_err_to_string(jb_err jb_error)
{
switch (jb_error)
{