1 const char errlog_rcs[] = "$Id: errlog.c,v 1.51 2007/05/11 11:51:34 fabiankeil Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/errlog.c,v $
6 * Purpose : Log errors to a designated destination in an elegant,
9 * Copyright : Written by and Copyright (C) 2001-2007 the SourceForge
10 * Privoxy team. http://www.privoxy.org/
12 * Based on the Internet Junkbuster originally written
13 * by and Copyright (C) 1997 Anonymous Coders and
14 * Junkbusters Corporation. http://www.junkbusters.com
16 * This program is free software; you can redistribute it
17 * and/or modify it under the terms of the GNU General
18 * Public License as published by the Free Software
19 * Foundation; either version 2 of the License, or (at
20 * your option) any later version.
22 * This program is distributed in the hope that it will
23 * be useful, but WITHOUT ANY WARRANTY; without even the
24 * implied warranty of MERCHANTABILITY or FITNESS FOR A
25 * PARTICULAR PURPOSE. See the GNU General Public
26 * License for more details.
28 * The GNU General Public License should be included with
29 * this file. If not, you can view it at
30 * http://www.gnu.org/copyleft/gpl.html
31 * or write to the Free Software Foundation, Inc., 59
32 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 * Revision 1.51 2007/05/11 11:51:34 fabiankeil
37 * Fix a type mismatch warning.
39 * Revision 1.50 2007/04/11 10:55:44 fabiankeil
40 * Enforce some assertions that could be triggered
41 * on mingw32 and other systems where we use threads
44 * Revision 1.49 2007/04/08 16:44:15 fabiankeil
45 * We need <sys/time.h> for gettimeofday(), not <time.h>.
47 * Revision 1.48 2007/03/31 13:33:28 fabiankeil
48 * Add alternative log_error() with timestamps
49 * that contain milliseconds and without using
50 * strcpy(), strcat() or sprintf().
52 * Revision 1.47 2006/11/28 15:25:15 fabiankeil
53 * Only unlink the pidfile if it's actually used.
55 * Revision 1.46 2006/11/13 19:05:51 fabiankeil
56 * Make pthread mutex locking more generic. Instead of
57 * checking for OSX and OpenBSD, check for FEATURE_PTHREAD
58 * and use mutex locking unless there is an _r function
59 * available. Better safe than sorry.
61 * Fixes "./configure --disable-pthread" and should result
62 * in less threading-related problems on pthread-using platforms,
63 * but it still doesn't fix BR#1122404.
65 * Revision 1.45 2006/08/21 11:15:54 david__schmidt
66 * MS Visual C++ build updates
68 * Revision 1.44 2006/08/18 16:03:16 david__schmidt
69 * Tweak for OS/2 build happiness.
71 * Revision 1.43 2006/08/03 02:46:41 david__schmidt
72 * Incorporate Fabian Keil's patch work:
73 * http://www.fabiankeil.de/sourcecode/privoxy/
75 * Revision 1.42 2006/07/18 14:48:46 david__schmidt
76 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
77 * with what was really the latest development (the v_3_0_branch branch)
79 * Revision 1.40.2.4 2005/04/03 20:10:50 david__schmidt
80 * Thanks to Jindrich Makovicka for a race condition fix for the log
81 * file. The race condition remains for non-pthread implementations.
82 * Reference patch #1175720.
84 * Revision 1.40.2.3 2003/03/07 03:41:04 david__schmidt
85 * Wrapping all *_r functions (the non-_r versions of them) with mutex
86 * semaphores for OSX. Hopefully this will take care of all of those pesky
89 * Revision 1.40.2.2 2002/09/28 00:30:57 david__schmidt
90 * Update error logging to give sane values for thread IDs on Mach kernels.
91 * It's still a hack, but at least it looks farily normal. We print the
92 * absolute value of the first 4 bytes of the pthread_t modded with 1000.
94 * Revision 1.40.2.1 2002/09/25 12:47:42 oes
95 * Make log_error safe against NULL string arguments
97 * Revision 1.40 2002/05/22 01:27:27 david__schmidt
99 * Add os2_socket_strerr mirroring w32_socket_strerr.
101 * Revision 1.39 2002/04/03 17:15:27 gliptak
102 * zero padding thread ids in log
104 * Revision 1.38 2002/03/31 17:18:59 jongfoster
105 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
107 * Revision 1.37 2002/03/27 14:32:43 david__schmidt
108 * More compiler warning message maintenance
110 * Revision 1.36 2002/03/26 22:29:54 swa
111 * we have a new homepage!
113 * Revision 1.35 2002/03/24 15:23:33 jongfoster
116 * Revision 1.34 2002/03/24 13:25:43 swa
117 * name change related issues
119 * Revision 1.33 2002/03/13 00:27:04 jongfoster
122 * Revision 1.32 2002/03/07 03:46:17 oes
123 * Fixed compiler warnings
125 * Revision 1.31 2002/03/06 23:02:57 jongfoster
128 * Revision 1.30 2002/03/05 22:43:45 david__schmidt
129 * - Better error reporting on OS/2
130 * - Fix double-slash comment (oops)
132 * Revision 1.29 2002/03/04 23:45:13 jongfoster
133 * Printing thread ID if using Win32 native threads
135 * Revision 1.28 2002/03/04 17:59:59 oes
136 * Deleted deletePidFile(), cosmetics
138 * Revision 1.27 2002/03/04 02:08:01 david__schmidt
139 * Enable web editing of actions file on OS/2 (it had been broken all this time!)
141 * Revision 1.26 2002/01/09 19:05:45 steudten
142 * Fix big memory leak.
144 * Revision 1.25 2002/01/09 14:32:08 oes
145 * Added support for gmtime_r and localtime_r.
147 * Revision 1.24 2001/12/30 14:07:32 steudten
148 * - Add signal handling (unix)
149 * - Add SIGHUP handler (unix)
150 * - Add creation of pidfile (unix)
151 * - Add action 'top' in rc file (RH)
152 * - Add entry 'SIGNALS' to manpage
153 * - Add exit message to logfile (unix)
155 * Revision 1.23 2001/11/07 00:02:13 steudten
156 * Add line number in error output for lineparsing for
157 * actionsfile and configfile.
158 * Special handling for CLF added.
160 * Revision 1.22 2001/11/05 23:43:05 steudten
161 * Add time+date to log files.
163 * Revision 1.21 2001/10/25 03:40:47 david__schmidt
164 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
165 * threads to call select() simultaneously. So, it's time to do a real, live,
166 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
167 * (native). Both versions will work, but using __OS2__ offers multi-threading.
169 * Revision 1.20 2001/09/16 23:04:34 jongfoster
172 * Revision 1.19 2001/09/13 20:08:06 jongfoster
173 * Adding support for LOG_LEVEL_CGI
175 * Revision 1.18 2001/09/10 11:27:24 oes
176 * Declaration of w32_socket_strerr now conditional
178 * Revision 1.17 2001/09/10 10:17:13 oes
179 * Removed unused variable; Fixed sprintf format
181 * Revision 1.16 2001/07/30 22:08:36 jongfoster
182 * Tidying up #defines:
183 * - All feature #defines are now of the form FEATURE_xxx
184 * - Permanently turned off WIN_GUI_EDIT
185 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
187 * Revision 1.15 2001/07/29 17:41:10 jongfoster
188 * Now prints thread ID for each message (pthreads only)
190 * Revision 1.14 2001/07/19 19:03:48 haroon
191 * - Added case for LOG_LEVEL_POPUPS
193 * Revision 1.13 2001/07/13 13:58:58 oes
194 * - Added case for LOG_LEVEL_DEANIMATE
195 * - Removed all #ifdef PCRS
197 * Revision 1.12 2001/06/09 10:55:28 jongfoster
198 * Changing BUFSIZ ==> BUFFER_SIZE
200 * Revision 1.11 2001/06/01 18:14:49 jongfoster
201 * Changing the calls to strerr() to check HAVE_STRERR (which is defined
202 * in config.h if appropriate) rather than the NO_STRERR macro.
204 * Revision 1.10 2001/05/29 11:52:21 oes
205 * Conditional compilation of w32_socket_error
207 * Revision 1.9 2001/05/28 16:15:17 jongfoster
208 * Improved reporting of errors under Win32.
210 * Revision 1.8 2001/05/26 17:25:14 jongfoster
211 * Added support for CLF (Common Log Format) and fixed LOG_LEVEL_LOG
213 * Revision 1.7 2001/05/26 15:21:28 jongfoster
214 * Activity animation in Win32 GUI now works even if debug==0
216 * Revision 1.6 2001/05/25 21:55:08 jongfoster
217 * Now cleans up properly on FATAL (removes taskbar icon etc)
219 * Revision 1.5 2001/05/22 18:46:04 oes
221 * - Enabled filtering banners by size rather than URL
222 * by adding patterns that replace all standard banner
223 * sizes with the "Junkbuster" gif to the re_filterfile
225 * - Enabled filtering WebBugs by providing a pattern
226 * which kills all 1x1 images
228 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
229 * which is selected by the (nonstandard and therefore
230 * capital) letter 'U' in the option string.
231 * It causes the quantifiers to be ungreedy by default.
232 * Appending a ? turns back to greedy (!).
234 * - Added a new interceptor ijb-send-banner, which
235 * sends back the "Junkbuster" gif. Without imagelist or
236 * MSIE detection support, or if tinygif = 1, or the
237 * URL isn't recognized as an imageurl, a lame HTML
238 * explanation is sent instead.
240 * - Added new feature, which permits blocking remote
241 * script redirects and firing back a local redirect
243 * The feature is conditionally compiled, i.e. it
244 * can be disabled with --disable-fast-redirects,
245 * plus it must be activated by a "fast-redirects"
246 * line in the config file, has its own log level
247 * and of course wants to be displayed by show-proxy-args
248 * Note: Boy, all the #ifdefs in 1001 locations and
249 * all the fumbling with configure.in and acconfig.h
250 * were *way* more work than the feature itself :-(
252 * - Because a generic redirect template was needed for
253 * this, tinygif = 3 now uses the same.
255 * - Moved GIFs, and other static HTTP response templates
260 * - Removed some >400 CRs again (Jon, you really worked
263 * Revision 1.4 2001/05/21 19:32:54 jongfoster
264 * Added another #ifdef _WIN_CONSOLE
266 * Revision 1.3 2001/05/20 01:11:40 jongfoster
267 * Added support for LOG_LEVEL_FATAL
268 * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE,
269 * and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER
271 * Revision 1.2 2001/05/17 22:42:01 oes
272 * - Cleaned CRLF's from the sources and related files
273 * - Repaired logging for REF and FRC
275 * Revision 1.1.1.1 2001/05/15 13:58:51 oes
276 * Initial import of version 2.9.3 source tree
279 *********************************************************************/
283 #include "miscutil.h"
290 #if defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY)
291 #define USE_NEW_LOG_ERROR
292 /* For gettimeofday() */
293 #include <sys/time.h>
294 #endif /* defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY) */
296 #if !defined(_WIN32) && !defined(__OS2__)
298 #endif /* !defined(_WIN32) && !defined(__OS2__) */
310 #endif /* ndef _WIN_CONSOLE */
311 #endif /* def _WIN32 */
313 #define inline __inline
314 #endif /* def _MSC_VER */
317 #include <sys/socket.h> /* For sock_errno */
326 const char errlog_h_rcs[] = ERRLOG_H_VERSION;
330 * LOG_LEVEL_FATAL cannot be turned off. (There are
331 * some exceptional situations where we need to get a
332 * message to the user).
334 #define LOG_LEVEL_MINIMUM LOG_LEVEL_FATAL
336 /* where to log (default: stderr) */
337 static FILE *logfp = NULL;
339 /* logging detail level. */
340 int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);
342 /* static functions */
343 static void fatal_error(const char * error_message);
345 static char *w32_socket_strerr(int errcode, char *tmp_buf);
348 static char *os2_socket_strerr(int errcode, char *tmp_buf);
351 #ifdef FEATURE_PTHREAD
352 static inline void lock_logfile()
354 pthread_mutex_lock(&log_mutex);
356 static inline void unlock_logfile()
358 pthread_mutex_unlock(&log_mutex);
360 static inline void lock_loginit()
362 pthread_mutex_lock(&log_init_mutex);
364 static inline void unlock_loginit()
366 pthread_mutex_unlock(&log_init_mutex);
368 #else /* ! FEATURE_PTHREAD */
370 * FIXME we need a cross-platform locking mechanism.
371 * The locking/unlocking functions below should be
372 * fleshed out for non-pthread implementations.
374 static inline void lock_logfile() {}
375 static inline void unlock_logfile() {}
376 static inline void lock_loginit() {}
377 static inline void unlock_loginit() {}
380 /*********************************************************************
382 * Function : fatal_error
384 * Description : Displays a fatal error to standard error (or, on
385 * a WIN32 GUI, to a dialog box), and exits
386 * JunkBuster with status code 1.
389 * 1 : error_message = The error message to display.
391 * Returns : Does not return.
393 *********************************************************************/
394 static void fatal_error(const char * error_message)
396 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
397 MessageBox(g_hwndLogFrame, error_message, "Privoxy Error",
398 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
400 /* Cleanup - remove taskbar icon etc. */
403 #else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
404 fputs(error_message, stderr);
405 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
418 /*********************************************************************
420 * Function : init_error_log
422 * Description : Initializes the logging module. Must call before
426 * 1 : prog_name = The program name.
427 * 2 : logfname = The logfile name, or NULL for stderr.
428 * 3 : debuglevel = The debugging level.
432 *********************************************************************/
433 void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
439 /* set the logging detail level */
440 debug = debuglevel | LOG_LEVEL_MINIMUM;
442 if ((logfp != NULL) && (logfp != stderr))
444 log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
453 /* set the designated log file */
456 if( NULL == (fp = fopen(logfname, "a")) )
458 log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: %s", logfname);
461 /* set logging to be completely unbuffered */
469 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
470 if (prog_name != NULL)
472 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
477 } /* init_error_log */
479 #if defined(USE_NEW_LOG_ERROR)
481 * Use an alternative log_error version and its helper functions.
483 * The code is mostly copied from the old log_error
484 * function but it's divided into multiple functions,
485 * doesn't use strcpy, strcat or sprintf and compiles
486 * with gcc43 without warnings (on FreeBSD that is).
488 * It should behave like the old log_error function with
491 * - too long format strings are logged truncated instead
492 * of completely replaced with the truncation warning,
493 * - its time stamps contain milliseconds.
496 /*********************************************************************
498 * Function : get_thread_id
500 * Description : Returns a number that is different for each thread.
502 * XXX: Should be moved elsewhere (miscutil.c?)
506 * Returns : thread_id
508 *********************************************************************/
509 long get_thread_id(void)
511 long this_thread = 1; /* was: pthread_t this_thread;*/
515 APIRET ulrc; /* XXX: I have no clue what this does */
518 /* FIXME get current thread id */
519 #ifdef FEATURE_PTHREAD
520 this_thread = (long)pthread_self();
523 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
524 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
525 * pthread_t is supposed to be opaque... but it's fairly random, though, so
526 * we make it mostly presentable.
528 this_thread = abs(this_thread % 1000);
529 #endif /* def __MACH__ */
530 #elif defined(_WIN32)
531 this_thread = GetCurrentThreadId();
532 #elif defined(__OS2__)
533 ulrc = DosGetInfoBlocks(&ptib, NULL);
535 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
536 #endif /* def FEATURE_PTHREAD */
542 /*********************************************************************
544 * Function : get_log_timestamp
546 * Description : Generates the time stamp for the log message prefix.
549 * 1 : buffer = Storage buffer
550 * 2 : buffer_size = Size of storage buffer
552 * Returns : Number of written characters or 0 for error.
554 *********************************************************************/
555 static inline size_t get_log_timestamp(char *buffer, size_t buffer_size)
560 struct timeval tv_now; /* XXX: stupid name */
561 gettimeofday(&tv_now, NULL);
562 long msecs = tv_now.tv_usec / 1000;
563 int msecs_length = 0;
567 #ifdef HAVE_LOCALTIME_R
568 tm_now = *localtime_r(&now, &tm_now);
569 #elif FEATURE_PTHREAD
570 pthread_mutex_lock(&localtime_mutex);
571 tm_now = *localtime(&now);
572 pthread_mutex_unlock(&localtime_mutex);
574 tm_now = *localtime(&now);
577 length = strftime(buffer, buffer_size, "%b %d %H:%M:%S", &tm_now);
580 msecs_length = snprintf(buffer+length, buffer_size - length, ".%.3ld", msecs);
582 if (msecs_length > 0)
584 length += (size_t)msecs_length;
595 /*********************************************************************
597 * Function : get_clf_timestamp
599 * Description : Generates a Common Log Format time string.
602 * 1 : buffer = Storage buffer
603 * 2 : buffer_size = Size of storage buffer
605 * Returns : Number of written characters or 0 for error.
607 *********************************************************************/
608 static inline size_t get_clf_timestamp(char *buffer, size_t buffer_size)
611 * Complex because not all OSs have tm_gmtoff or
612 * the %z field in strftime()
617 #ifdef HAVE_LOCALTIME_R
626 gmt = *gmtime_r(&now, &gmt);
627 #elif FEATURE_PTHREAD
628 pthread_mutex_lock(&gmtime_mutex);
630 pthread_mutex_unlock(&gmtime_mutex);
634 #ifdef HAVE_LOCALTIME_R
635 tm_now = localtime_r(&now, &dummy);
636 #elif FEATURE_PTHREAD
637 pthread_mutex_lock(&localtime_mutex);
638 tm_now = localtime(&now);
639 pthread_mutex_unlock(&localtime_mutex);
641 tm_now = localtime(&now);
643 days = tm_now->tm_yday - gmt.tm_yday;
644 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
645 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
647 length = strftime(buffer, buffer_size, "%d/%b/%Y:%H:%M:%S ", tm_now);
651 tz_length = snprintf(buffer+length, buffer_size-length,
652 "%+03d%02d", mins / 60, abs(mins) % 60);
656 length += (size_t)tz_length;
667 /*********************************************************************
669 * Function : get_log_level_string
671 * Description : Translates a numerical loglevel into a string.
674 * 1 : loglevel = LOG_LEVEL_FOO
676 * Returns : Log level string.
678 *********************************************************************/
679 inline const char *get_log_level_string(int loglevel)
681 char *log_level_string = NULL;
683 assert(0 < loglevel);
687 case LOG_LEVEL_ERROR:
688 log_level_string = "Error";
690 case LOG_LEVEL_FATAL:
691 log_level_string = "Fatal error";
694 log_level_string = "Request";
696 case LOG_LEVEL_CONNECT:
697 log_level_string = "Connect";
700 log_level_string = "Writing";
702 case LOG_LEVEL_HEADER:
703 log_level_string = "Header";
706 log_level_string = "Info";
708 case LOG_LEVEL_RE_FILTER:
709 log_level_string = "Re-Filter";
711 #ifdef FEATURE_FORCE_LOAD
712 case LOG_LEVEL_FORCE:
713 log_level_string = "Force";
715 #endif /* def FEATURE_FORCE_LOAD */
716 #ifdef FEATURE_FAST_REDIRECTS
717 case LOG_LEVEL_REDIRECTS:
718 log_level_string = "Redirect";
720 #endif /* def FEATURE_FAST_REDIRECTS */
721 case LOG_LEVEL_DEANIMATE:
722 log_level_string = "Gif-Deanimate";
724 #ifdef FEATURE_KILL_POPUPS
725 case LOG_LEVEL_POPUPS:
726 log_level_string = "Kill-Popups";
728 #endif /* def FEATURE_KILL_POPUPS */
730 log_level_string = "CGI";
733 log_level_string = "Unknown log level";
736 assert(NULL != log_level_string);
738 return log_level_string;
742 /*********************************************************************
744 * Function : log_error
746 * Description : This is the error-reporting and logging function.
749 * 1 : loglevel = the type of message to be logged
750 * 2 : fmt = the main string we want logged, printf-like
751 * 3 : ... = arguments to be inserted in fmt (printf-like).
755 *********************************************************************/
756 void log_error(int loglevel, const char *fmt, ...)
760 static char *outbuf_save = NULL;
761 char tempbuf[BUFFER_SIZE];
763 const char * src = fmt;
767 * XXX: Make this a config option,
768 * why else do we allocate instead of using
771 size_t log_buffer_size = BUFFER_SIZE;
773 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
775 * Irrespective of debug setting, a GET/POST/CONNECT makes
776 * the taskbar icon animate. (There is an option to disable
777 * this but checking that is handled inside LogShowActivity()).
779 if (loglevel == LOG_LEVEL_GPC)
783 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
785 /* verify if loglevel applies to current settings and bail out if negative */
786 if ((loglevel & debug) == 0)
791 thread_id = get_thread_id();
792 get_log_timestamp(timestamp, sizeof(timestamp));
794 /* protect the whole function because of the static buffer (outbuf) */
797 if (NULL == outbuf_save)
799 outbuf_save = (char*)zalloc(log_buffer_size + 1); /* +1 for paranoia */
800 if (NULL == outbuf_save)
802 snprintf(tempbuf, sizeof(tempbuf),
803 "%s Privoxy(%08lx) Fatal error: log_error() failed to allocate buffer memory.\n"
804 "\nExiting.", timestamp, thread_id);
809 fputs(tempbuf, logfp);
811 fatal_error(tempbuf); /* Exit */
814 outbuf = outbuf_save;
817 * Memsetting the whole buffer to zero (in theory)
818 * makes things easier later on.
820 memset(outbuf, 0, log_buffer_size);
822 /* Add prefix for everything but Common Log Format messages */
823 if (loglevel != LOG_LEVEL_CLF)
825 length = (size_t)snprintf(outbuf, log_buffer_size, "%s Privoxy(%08lx) %s: ",
826 timestamp, thread_id, get_log_level_string(loglevel));
829 /* get ready to scan var. args. */
832 /* build formatted message from fmt and var-args */
833 while ((*src) && (length < log_buffer_size-2))
835 const char *sval = NULL; /* %N string */
836 int ival; /* %N string length or an error code */
837 unsigned uval; /* %u value */
838 long lval; /* %l value */
839 unsigned long ulval; /* %ul value */
841 const char *format_string = tempbuf;
846 outbuf[length++] = ch;
848 * XXX: Only necessary on platforms which don't use pthread
849 * mutexes (mingw32 for example), where multiple threads can
850 * write to the buffer at the same time.
852 outbuf[length] = '\0';
855 outbuf[length] = '\0';
863 ival = va_arg( ap, int );
864 snprintf(tempbuf, sizeof(tempbuf), "%d", ival);
867 uval = va_arg( ap, unsigned );
868 snprintf(tempbuf, sizeof(tempbuf), "%u", uval);
871 /* this is a modifier that must be followed by u or d */
875 lval = va_arg( ap, long );
876 snprintf(tempbuf, sizeof(tempbuf), "%ld", lval);
880 ulval = va_arg( ap, unsigned long );
881 snprintf(tempbuf, sizeof(tempbuf), "%lu", ulval);
885 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
886 loglevel = LOG_LEVEL_FATAL;
891 * Note that char paramaters are converted to int, so we need to
892 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
894 tempbuf[0] = (char) va_arg(ap, int);
898 format_string = va_arg(ap, char *);
899 if (format_string == NULL)
901 format_string = "[null]";
906 * Non-standard: Print a counted unterminated string.
907 * Takes 2 parameters: int length, const char * string.
909 ival = va_arg(ap, int);
910 sval = va_arg(ap, char *);
913 format_string = "[null]";
919 /* That's ok (but stupid) */
925 * That's not ok (and even more stupid)
928 format_string = "[counted string lenght < 0]";
931 else if (ival >= sizeof(tempbuf))
934 * String is too long, copy as much as possible.
935 * It will be further truncated later.
937 memcpy(tempbuf, sval, sizeof(tempbuf)-1);
938 tempbuf[sizeof(tempbuf)-1] = '\0';
942 memcpy(tempbuf, sval, (size_t) ival);
943 tempbuf[ival] = '\0';
947 /* Non-standard: Print error code from errno */
949 ival = WSAGetLastError();
950 format_string = w32_socket_strerr(ival, tempbuf);
955 format_string = os2_socket_strerr(ival, tempbuf);
960 format_string = strerror(ival);
962 #else /* ifndef _WIN32 */
965 format_string = strerror(ival);
966 #else /* ifndef HAVE_STRERROR */
967 format_string = NULL;
968 #endif /* ndef HAVE_STRERROR */
971 snprintf(tempbuf, sizeof(tempbuf), "(errno = %d)", ival);
973 #endif /* ndef _WIN32 */
976 /* Non-standard: Print a Common Log File timestamp */
977 get_clf_timestamp(tempbuf, sizeof(tempbuf));
980 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
981 loglevel = LOG_LEVEL_FATAL;
985 assert(length < log_buffer_size);
986 length += strlcpy(outbuf + length, format_string, log_buffer_size - length);
988 if (length >= log_buffer_size-2)
990 static char warning[] = "... [too long, truncated]";
992 length = log_buffer_size - sizeof(warning) - 1;
993 length += strlcpy(outbuf + length, warning, log_buffer_size - length);
994 assert(length < log_buffer_size);
1000 /* done with var. args */
1003 assert(length < log_buffer_size);
1004 length += strlcpy(outbuf + length, "\n", log_buffer_size - length);
1006 /* Some sanity checks */
1007 if (!(length < log_buffer_size)
1008 || !(outbuf[log_buffer_size-1] == '\0')
1009 || !(outbuf[log_buffer_size] == '\0')
1012 /* Repeat as assertions */
1013 assert(length < log_buffer_size);
1014 assert(outbuf[log_buffer_size-1] == '\0');
1016 * outbuf's real size is log_buffer_size+1,
1017 * so while this looks like an off-by-one,
1018 * we're only checking our paranoia byte.
1020 assert(outbuf[log_buffer_size] == '\0');
1022 snprintf(outbuf, log_buffer_size,
1023 "%s Privoxy(%08lx) Fatal error: log_error()'s sanity checks failed. length: %d\n"
1024 "Exiting.", timestamp, thread_id, (int)length);
1025 loglevel = LOG_LEVEL_FATAL;
1028 /* deal with glibc stupidity - it won't let you initialize logfp */
1029 /* XXX: Still necessary? */
1035 fputs(outbuf_save, logfp);
1037 if (loglevel == LOG_LEVEL_FATAL)
1039 fatal_error(outbuf_save);
1040 /* Never get here */
1045 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1046 /* Write to display */
1047 LogPutString(outbuf_save);
1048 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1052 #else /* use traditional log_error version */
1054 /*********************************************************************
1056 * Function : log_error
1058 * Description : This is the error-reporting and logging function.
1061 * 1 : loglevel = the type of message to be logged
1062 * 2 : fmt = the main string we want logged, printf-like
1063 * 3 : ... = arguments to be inserted in fmt (printf-like).
1067 *********************************************************************/
1068 void log_error(int loglevel, const char *fmt, ...)
1072 static char *outbuf_save = NULL;
1073 const char * src = fmt;
1075 long this_thread = 1; /* was: pthread_t this_thread;*/
1079 #endif /* __OS2__ */
1081 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1083 * Irrespective of debug setting, a GET/POST/CONNECT makes
1084 * the taskbar icon animate. (There is an option to disable
1085 * this but checking that is handled inside LogShowActivity()).
1087 if (loglevel == LOG_LEVEL_GPC)
1091 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1093 /* verify if loglevel applies to current settings and bail out if negative */
1094 if ((loglevel & debug) == 0)
1099 /* protect the whole function because of the static buffer (outbuf) */
1102 /* FIXME get current thread id */
1103 #ifdef FEATURE_PTHREAD
1104 this_thread = (long)pthread_self();
1107 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
1108 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
1109 * pthread_t is supposed to be opaque... but it's fairly random, though, so
1110 * we make it mostly presentable.
1112 this_thread = abs(this_thread % 1000);
1113 #endif /* def __MACH__ */
1114 #elif defined(_WIN32)
1115 this_thread = GetCurrentThreadId();
1116 #elif defined(__OS2__)
1117 ulrc = DosGetInfoBlocks(&ptib, NULL);
1119 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
1120 #endif /* def FEATURE_PTHREAD */
1124 outbuf_save = outbuf = (char*)malloc(BUFFER_SIZE);
1125 if (NULL == outbuf_save)
1127 fatal_error("Privoxy failed to allocate log buffer.");
1130 outbuf = outbuf_save;
1134 * Write timestamp into tempbuf.
1136 * Complex because not all OSs have tm_gmtoff or
1137 * the %z field in strftime()
1142 #ifdef HAVE_LOCALTIME_R
1143 tm_now = *localtime_r(&now, &tm_now);
1144 #elif FEATURE_PTHREAD
1145 pthread_mutex_lock(&localtime_mutex);
1146 tm_now = *localtime (&now);
1147 pthread_mutex_unlock(&localtime_mutex);
1149 tm_now = *localtime (&now);
1151 strftime(outbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
1152 outbuf += strlen( outbuf );
1156 case LOG_LEVEL_ERROR:
1157 outc = sprintf(outbuf, "Privoxy(%08lx) Error: ", this_thread);
1159 case LOG_LEVEL_FATAL:
1160 outc = sprintf(outbuf, "Privoxy(%08lx) Fatal error: ", this_thread);
1163 outc = sprintf(outbuf, "Privoxy(%08lx) Request: ", this_thread);
1165 case LOG_LEVEL_CONNECT:
1166 outc = sprintf(outbuf, "Privoxy(%08lx) Connect: ", this_thread);
1169 outc = sprintf(outbuf, "Privoxy(%08lx) Writing: ", this_thread);
1171 case LOG_LEVEL_HEADER:
1172 outc = sprintf(outbuf, "Privoxy(%08lx) Header: ", this_thread);
1174 case LOG_LEVEL_INFO:
1175 outc = sprintf(outbuf, "Privoxy(%08lx) Info: ", this_thread);
1177 case LOG_LEVEL_RE_FILTER:
1178 outc = sprintf(outbuf, "Privoxy(%08lx) Re-Filter: ", this_thread);
1180 #ifdef FEATURE_FORCE_LOAD
1181 case LOG_LEVEL_FORCE:
1182 outc = sprintf(outbuf, "Privoxy(%08lx) Force: ", this_thread);
1184 #endif /* def FEATURE_FORCE_LOAD */
1185 #ifdef FEATURE_FAST_REDIRECTS
1186 case LOG_LEVEL_REDIRECTS:
1187 outc = sprintf(outbuf, "Privoxy(%08lx) Redirect: ", this_thread);
1189 #endif /* def FEATURE_FAST_REDIRECTS */
1190 case LOG_LEVEL_DEANIMATE:
1191 outc = sprintf(outbuf, "Privoxy(%08lx) Gif-Deanimate: ", this_thread);
1194 outbuf = outbuf_save;
1198 #ifdef FEATURE_KILL_POPUPS
1199 case LOG_LEVEL_POPUPS:
1200 outc = sprintf(outbuf, "Privoxy(%08lx) Kill-Popups: ", this_thread);
1202 #endif /* def FEATURE_KILL_POPUPS */
1204 outc = sprintf(outbuf, "Privoxy(%08lx) CGI: ", this_thread);
1207 outc = sprintf(outbuf, "Privoxy(%08lx) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
1211 /* get ready to scan var. args. */
1212 va_start( ap, fmt );
1214 /* build formatted message from fmt and var-args */
1215 while ((*src) && (outc < BUFFER_SIZE-2))
1217 char tempbuf[BUFFER_SIZE];
1222 unsigned long ulval;
1229 outbuf[outc++] = ch;
1236 outbuf[outc++] = '%';
1239 ival = va_arg( ap, int );
1241 outc += sprintf(tempbuf, "%d", ival);
1242 if (outc < BUFFER_SIZE-1)
1244 strcpy(outbuf + oldoutc, tempbuf);
1248 outbuf[oldoutc] = '\0';
1252 uval = va_arg( ap, unsigned );
1254 outc += sprintf(tempbuf, "%u", uval);
1255 if (outc < BUFFER_SIZE-1)
1257 strcpy(outbuf + oldoutc, tempbuf);
1261 outbuf[oldoutc] = '\0';
1265 /* this is a modifier that must be followed by u or d */
1269 lval = va_arg( ap, long );
1271 outc += sprintf(tempbuf, "%ld", lval);
1275 ulval = va_arg( ap, unsigned long );
1277 outc += sprintf(tempbuf, "%lu", ulval);
1282 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1284 "Exiting.", this_thread, fmt);
1289 fputs(outbuf, logfp);
1290 fatal_error(outbuf);
1291 /* Never get here */
1294 if (outc < BUFFER_SIZE-1)
1296 strcpy(outbuf + oldoutc, tempbuf);
1300 outbuf[oldoutc] = '\0';
1305 * Note that char paramaters are converted to int, so we need to
1306 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
1308 outbuf[outc++] = (char) va_arg( ap, int );
1311 sval = va_arg( ap, char * );
1317 outc += strlen(sval);
1318 if (outc < BUFFER_SIZE-1)
1320 strcpy(outbuf + oldoutc, sval);
1324 outbuf[oldoutc] = '\0';
1328 /* Non-standard: Print a counted string. Takes 2 parameters:
1329 * int length, const char * string
1331 ival = va_arg( ap, int );
1332 sval = va_arg( ap, char * );
1343 if (outc < BUFFER_SIZE-1)
1345 memcpy(outbuf + oldoutc, sval, (size_t) ival);
1349 outbuf[oldoutc] = '\0';
1353 /* Non-standard: Print error code from errno */
1355 ival = WSAGetLastError();
1356 sval = w32_socket_strerr(ival, tempbuf);
1358 ival = sock_errno();
1360 sval = os2_socket_strerr(ival, tempbuf);
1364 sval = strerror(ival);
1366 #else /* ifndef _WIN32 */
1368 #ifdef HAVE_STRERROR
1369 sval = strerror(ival);
1370 #else /* ifndef HAVE_STRERROR */
1372 #endif /* ndef HAVE_STRERROR */
1375 sprintf(tempbuf, "(errno = %d)", ival);
1378 #endif /* ndef _WIN32 */
1380 outc += strlen(sval);
1381 if (outc < BUFFER_SIZE-1)
1383 strcpy(outbuf + oldoutc, sval);
1387 outbuf[oldoutc] = '\0';
1391 /* Non-standard: Print a Common Log File timestamp */
1394 * Write timestamp into tempbuf.
1396 * Complex because not all OSs have tm_gmtoff or
1397 * the %z field in strftime()
1402 #ifdef HAVE_LOCALTIME_R
1405 int days, hrs, mins;
1407 #ifdef HAVE_GMTIME_R
1408 gmt = *gmtime_r(&now, &gmt);
1409 #elif FEATURE_PTHREAD
1410 pthread_mutex_lock(&gmtime_mutex);
1411 gmt = *gmtime(&now);
1412 pthread_mutex_unlock(&gmtime_mutex);
1414 gmt = *gmtime(&now);
1416 #ifdef HAVE_LOCALTIME_R
1417 tm_now = localtime_r(&now, &dummy);
1418 #elif FEATURE_PTHREAD
1419 pthread_mutex_lock(&localtime_mutex);
1420 tm_now = localtime (&now);
1421 pthread_mutex_unlock(&localtime_mutex);
1423 tm_now = localtime (&now);
1425 days = tm_now->tm_yday - gmt.tm_yday;
1426 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
1427 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
1428 strftime (tempbuf, BUFFER_SIZE-6, "%d/%b/%Y:%H:%M:%S ", tm_now);
1429 sprintf (tempbuf + strlen(tempbuf), "%+03d%02d", mins / 60, abs(mins) % 60);
1432 outc += strlen(tempbuf);
1433 if (outc < BUFFER_SIZE-1)
1435 strcpy(outbuf + oldoutc, tempbuf);
1439 outbuf[oldoutc] = '\0';
1443 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1445 "Exiting.", this_thread, fmt);
1450 fputs(outbuf_save, logfp);
1452 fatal_error(outbuf_save);
1453 /* Never get here */
1458 } /* for( p ... ) */
1460 /* done with var. args */
1463 if (outc >= BUFFER_SIZE-2)
1465 /* insufficient room for newline and trailing null. */
1467 static const char warning[] = "... [too long, truncated]\n";
1469 if (outc < BUFFER_SIZE)
1471 /* Need to add terminating null in this case. */
1472 outbuf[outc] = '\0';
1475 /* Truncate output */
1476 outbuf[BUFFER_SIZE - sizeof(warning)] = '\0';
1478 /* Append warning */
1479 strcat(outbuf, warning);
1483 /* Add terminating newline and null */
1484 outbuf[outc++] = '\n';
1485 outbuf[outc] = '\0';
1488 /* deal with glibc stupidity - it won't let you initialize logfp */
1494 fputs(outbuf_save, logfp);
1496 if (loglevel == LOG_LEVEL_FATAL)
1498 fatal_error(outbuf_save);
1499 /* Never get here */
1504 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1505 /* Write to display */
1506 LogPutString(outbuf_save);
1507 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1510 #endif /* defined(USE_NEW_LOG_ERROR) */
1513 /*********************************************************************
1515 * Function : jb_err_to_string
1517 * Description : Translates JB_ERR_FOO codes into strings.
1519 * XXX: the type of error codes is jb_err
1520 * but the typedef'inition is currently not
1521 * visible to all files that include errlog.h.
1524 * 1 : error = a valid jb_err code
1526 * Returns : A string with the jb_err translation
1528 *********************************************************************/
1529 const char *jb_err_to_string(int error)
1534 return "Success, no error";
1536 return "Out of memory";
1537 case JB_ERR_CGI_PARAMS:
1538 return "Missing or corrupt CGI parameters";
1540 return "Error opening, reading or writing a file";
1542 return "Parse error";
1543 case JB_ERR_MODIFIED:
1544 return "File has been modified outside of the CGI actions editor.";
1545 case JB_ERR_COMPRESS:
1546 return "(De)compression failure";
1549 return "Unknown error";
1552 return "Internal error";
1556 /*********************************************************************
1558 * Function : w32_socket_strerr
1560 * Description : Translate the return value from WSAGetLastError()
1564 * 1 : errcode = The return value from WSAGetLastError().
1565 * 2 : tmp_buf = A temporary buffer that might be used to
1568 * Returns : String representing the error code. This may be
1569 * a global string constant or a string stored in
1572 *********************************************************************/
1573 static char *w32_socket_strerr(int errcode, char *tmp_buf)
1575 #define TEXT_FOR_ERROR(code,text) \
1576 if (errcode == code) \
1578 return #code " - " text; \
1581 TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
1582 TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
1583 TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
1584 TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
1585 TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
1586 TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
1587 TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
1588 TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
1589 TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
1590 TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
1591 TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
1592 TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
1593 TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
1594 TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
1595 TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
1596 TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
1597 TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
1598 TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
1599 TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
1600 TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
1601 TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
1602 TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
1603 TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
1604 TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
1605 TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
1606 TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
1607 TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
1608 TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
1609 TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
1610 TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
1611 TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
1612 TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
1613 TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
1614 TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
1615 TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
1616 TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
1617 TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
1618 TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
1619 TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
1620 TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
1621 TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
1622 TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
1624 * The following error codes are documented in the Microsoft WinSock
1625 * reference guide, but don't actually exist.
1627 * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
1628 * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
1629 * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
1630 * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
1631 * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
1632 * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
1633 * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
1634 * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
1635 * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
1636 * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
1639 sprintf(tmp_buf, "(error number %d)", errcode);
1642 #endif /* def _WIN32 */
1646 /*********************************************************************
1648 * Function : os2_socket_strerr
1650 * Description : Translate the return value from sock_errno()
1654 * 1 : errcode = The return value from sock_errno().
1655 * 2 : tmp_buf = A temporary buffer that might be used to
1658 * Returns : String representing the error code. This may be
1659 * a global string constant or a string stored in
1662 *********************************************************************/
1663 static char *os2_socket_strerr(int errcode, char *tmp_buf)
1665 #define TEXT_FOR_ERROR(code,text) \
1666 if (errcode == code) \
1668 return #code " - " text; \
1671 TEXT_FOR_ERROR(SOCEPERM , "Not owner.")
1672 TEXT_FOR_ERROR(SOCESRCH , "No such process.")
1673 TEXT_FOR_ERROR(SOCEINTR , "Interrupted system call.")
1674 TEXT_FOR_ERROR(SOCENXIO , "No such device or address.")
1675 TEXT_FOR_ERROR(SOCEBADF , "Bad file number.")
1676 TEXT_FOR_ERROR(SOCEACCES , "Permission denied.")
1677 TEXT_FOR_ERROR(SOCEFAULT , "Bad address.")
1678 TEXT_FOR_ERROR(SOCEINVAL , "Invalid argument.")
1679 TEXT_FOR_ERROR(SOCEMFILE , "Too many open files.")
1680 TEXT_FOR_ERROR(SOCEPIPE , "Broken pipe.")
1681 TEXT_FOR_ERROR(SOCEWOULDBLOCK , "Operation would block.")
1682 TEXT_FOR_ERROR(SOCEINPROGRESS , "Operation now in progress.")
1683 TEXT_FOR_ERROR(SOCEALREADY , "Operation already in progress.")
1684 TEXT_FOR_ERROR(SOCENOTSOCK , "Socket operation on non-socket.")
1685 TEXT_FOR_ERROR(SOCEDESTADDRREQ , "Destination address required.")
1686 TEXT_FOR_ERROR(SOCEMSGSIZE , "Message too long.")
1687 TEXT_FOR_ERROR(SOCEPROTOTYPE , "Protocol wrong type for socket.")
1688 TEXT_FOR_ERROR(SOCENOPROTOOPT , "Protocol not available.")
1689 TEXT_FOR_ERROR(SOCEPROTONOSUPPORT, "Protocol not supported.")
1690 TEXT_FOR_ERROR(SOCESOCKTNOSUPPORT, "Socket type not supported.")
1691 TEXT_FOR_ERROR(SOCEOPNOTSUPP , "Operation not supported.")
1692 TEXT_FOR_ERROR(SOCEPFNOSUPPORT , "Protocol family not supported.")
1693 TEXT_FOR_ERROR(SOCEAFNOSUPPORT , "Address family not supported by protocol family.")
1694 TEXT_FOR_ERROR(SOCEADDRINUSE , "Address already in use.")
1695 TEXT_FOR_ERROR(SOCEADDRNOTAVAIL , "Can't assign requested address.")
1696 TEXT_FOR_ERROR(SOCENETDOWN , "Network is down.")
1697 TEXT_FOR_ERROR(SOCENETUNREACH , "Network is unreachable.")
1698 TEXT_FOR_ERROR(SOCENETRESET , "Network dropped connection on reset.")
1699 TEXT_FOR_ERROR(SOCECONNABORTED , "Software caused connection abort.")
1700 TEXT_FOR_ERROR(SOCECONNRESET , "Connection reset by peer.")
1701 TEXT_FOR_ERROR(SOCENOBUFS , "No buffer space available.")
1702 TEXT_FOR_ERROR(SOCEISCONN , "Socket is already connected.")
1703 TEXT_FOR_ERROR(SOCENOTCONN , "Socket is not connected.")
1704 TEXT_FOR_ERROR(SOCESHUTDOWN , "Can't send after socket shutdown.")
1705 TEXT_FOR_ERROR(SOCETOOMANYREFS , "Too many references: can't splice.")
1706 TEXT_FOR_ERROR(SOCETIMEDOUT , "Operation timed out.")
1707 TEXT_FOR_ERROR(SOCECONNREFUSED , "Connection refused.")
1708 TEXT_FOR_ERROR(SOCELOOP , "Too many levels of symbolic links.")
1709 TEXT_FOR_ERROR(SOCENAMETOOLONG , "File name too long.")
1710 TEXT_FOR_ERROR(SOCEHOSTDOWN , "Host is down.")
1711 TEXT_FOR_ERROR(SOCEHOSTUNREACH , "No route to host.")
1712 TEXT_FOR_ERROR(SOCENOTEMPTY , "Directory not empty.")
1713 TEXT_FOR_ERROR(SOCEOS2ERR , "OS/2 Error.")
1715 sprintf(tmp_buf, "(error number %d)", errcode);
1718 #endif /* def __OS2__ */