1 const char errlog_rcs[] = "$Id: errlog.c,v 1.50 2007/04/11 10:55:44 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.50 2007/04/11 10:55:44 fabiankeil
37 * Enforce some assertions that could be triggered
38 * on mingw32 and other systems where we use threads
41 * Revision 1.49 2007/04/08 16:44:15 fabiankeil
42 * We need <sys/time.h> for gettimeofday(), not <time.h>.
44 * Revision 1.48 2007/03/31 13:33:28 fabiankeil
45 * Add alternative log_error() with timestamps
46 * that contain milliseconds and without using
47 * strcpy(), strcat() or sprintf().
49 * Revision 1.47 2006/11/28 15:25:15 fabiankeil
50 * Only unlink the pidfile if it's actually used.
52 * Revision 1.46 2006/11/13 19:05:51 fabiankeil
53 * Make pthread mutex locking more generic. Instead of
54 * checking for OSX and OpenBSD, check for FEATURE_PTHREAD
55 * and use mutex locking unless there is an _r function
56 * available. Better safe than sorry.
58 * Fixes "./configure --disable-pthread" and should result
59 * in less threading-related problems on pthread-using platforms,
60 * but it still doesn't fix BR#1122404.
62 * Revision 1.45 2006/08/21 11:15:54 david__schmidt
63 * MS Visual C++ build updates
65 * Revision 1.44 2006/08/18 16:03:16 david__schmidt
66 * Tweak for OS/2 build happiness.
68 * Revision 1.43 2006/08/03 02:46:41 david__schmidt
69 * Incorporate Fabian Keil's patch work:
70 * http://www.fabiankeil.de/sourcecode/privoxy/
72 * Revision 1.42 2006/07/18 14:48:46 david__schmidt
73 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
74 * with what was really the latest development (the v_3_0_branch branch)
76 * Revision 1.40.2.4 2005/04/03 20:10:50 david__schmidt
77 * Thanks to Jindrich Makovicka for a race condition fix for the log
78 * file. The race condition remains for non-pthread implementations.
79 * Reference patch #1175720.
81 * Revision 1.40.2.3 2003/03/07 03:41:04 david__schmidt
82 * Wrapping all *_r functions (the non-_r versions of them) with mutex
83 * semaphores for OSX. Hopefully this will take care of all of those pesky
86 * Revision 1.40.2.2 2002/09/28 00:30:57 david__schmidt
87 * Update error logging to give sane values for thread IDs on Mach kernels.
88 * It's still a hack, but at least it looks farily normal. We print the
89 * absolute value of the first 4 bytes of the pthread_t modded with 1000.
91 * Revision 1.40.2.1 2002/09/25 12:47:42 oes
92 * Make log_error safe against NULL string arguments
94 * Revision 1.40 2002/05/22 01:27:27 david__schmidt
96 * Add os2_socket_strerr mirroring w32_socket_strerr.
98 * Revision 1.39 2002/04/03 17:15:27 gliptak
99 * zero padding thread ids in log
101 * Revision 1.38 2002/03/31 17:18:59 jongfoster
102 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
104 * Revision 1.37 2002/03/27 14:32:43 david__schmidt
105 * More compiler warning message maintenance
107 * Revision 1.36 2002/03/26 22:29:54 swa
108 * we have a new homepage!
110 * Revision 1.35 2002/03/24 15:23:33 jongfoster
113 * Revision 1.34 2002/03/24 13:25:43 swa
114 * name change related issues
116 * Revision 1.33 2002/03/13 00:27:04 jongfoster
119 * Revision 1.32 2002/03/07 03:46:17 oes
120 * Fixed compiler warnings
122 * Revision 1.31 2002/03/06 23:02:57 jongfoster
125 * Revision 1.30 2002/03/05 22:43:45 david__schmidt
126 * - Better error reporting on OS/2
127 * - Fix double-slash comment (oops)
129 * Revision 1.29 2002/03/04 23:45:13 jongfoster
130 * Printing thread ID if using Win32 native threads
132 * Revision 1.28 2002/03/04 17:59:59 oes
133 * Deleted deletePidFile(), cosmetics
135 * Revision 1.27 2002/03/04 02:08:01 david__schmidt
136 * Enable web editing of actions file on OS/2 (it had been broken all this time!)
138 * Revision 1.26 2002/01/09 19:05:45 steudten
139 * Fix big memory leak.
141 * Revision 1.25 2002/01/09 14:32:08 oes
142 * Added support for gmtime_r and localtime_r.
144 * Revision 1.24 2001/12/30 14:07:32 steudten
145 * - Add signal handling (unix)
146 * - Add SIGHUP handler (unix)
147 * - Add creation of pidfile (unix)
148 * - Add action 'top' in rc file (RH)
149 * - Add entry 'SIGNALS' to manpage
150 * - Add exit message to logfile (unix)
152 * Revision 1.23 2001/11/07 00:02:13 steudten
153 * Add line number in error output for lineparsing for
154 * actionsfile and configfile.
155 * Special handling for CLF added.
157 * Revision 1.22 2001/11/05 23:43:05 steudten
158 * Add time+date to log files.
160 * Revision 1.21 2001/10/25 03:40:47 david__schmidt
161 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
162 * threads to call select() simultaneously. So, it's time to do a real, live,
163 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
164 * (native). Both versions will work, but using __OS2__ offers multi-threading.
166 * Revision 1.20 2001/09/16 23:04:34 jongfoster
169 * Revision 1.19 2001/09/13 20:08:06 jongfoster
170 * Adding support for LOG_LEVEL_CGI
172 * Revision 1.18 2001/09/10 11:27:24 oes
173 * Declaration of w32_socket_strerr now conditional
175 * Revision 1.17 2001/09/10 10:17:13 oes
176 * Removed unused variable; Fixed sprintf format
178 * Revision 1.16 2001/07/30 22:08:36 jongfoster
179 * Tidying up #defines:
180 * - All feature #defines are now of the form FEATURE_xxx
181 * - Permanently turned off WIN_GUI_EDIT
182 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
184 * Revision 1.15 2001/07/29 17:41:10 jongfoster
185 * Now prints thread ID for each message (pthreads only)
187 * Revision 1.14 2001/07/19 19:03:48 haroon
188 * - Added case for LOG_LEVEL_POPUPS
190 * Revision 1.13 2001/07/13 13:58:58 oes
191 * - Added case for LOG_LEVEL_DEANIMATE
192 * - Removed all #ifdef PCRS
194 * Revision 1.12 2001/06/09 10:55:28 jongfoster
195 * Changing BUFSIZ ==> BUFFER_SIZE
197 * Revision 1.11 2001/06/01 18:14:49 jongfoster
198 * Changing the calls to strerr() to check HAVE_STRERR (which is defined
199 * in config.h if appropriate) rather than the NO_STRERR macro.
201 * Revision 1.10 2001/05/29 11:52:21 oes
202 * Conditional compilation of w32_socket_error
204 * Revision 1.9 2001/05/28 16:15:17 jongfoster
205 * Improved reporting of errors under Win32.
207 * Revision 1.8 2001/05/26 17:25:14 jongfoster
208 * Added support for CLF (Common Log Format) and fixed LOG_LEVEL_LOG
210 * Revision 1.7 2001/05/26 15:21:28 jongfoster
211 * Activity animation in Win32 GUI now works even if debug==0
213 * Revision 1.6 2001/05/25 21:55:08 jongfoster
214 * Now cleans up properly on FATAL (removes taskbar icon etc)
216 * Revision 1.5 2001/05/22 18:46:04 oes
218 * - Enabled filtering banners by size rather than URL
219 * by adding patterns that replace all standard banner
220 * sizes with the "Junkbuster" gif to the re_filterfile
222 * - Enabled filtering WebBugs by providing a pattern
223 * which kills all 1x1 images
225 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
226 * which is selected by the (nonstandard and therefore
227 * capital) letter 'U' in the option string.
228 * It causes the quantifiers to be ungreedy by default.
229 * Appending a ? turns back to greedy (!).
231 * - Added a new interceptor ijb-send-banner, which
232 * sends back the "Junkbuster" gif. Without imagelist or
233 * MSIE detection support, or if tinygif = 1, or the
234 * URL isn't recognized as an imageurl, a lame HTML
235 * explanation is sent instead.
237 * - Added new feature, which permits blocking remote
238 * script redirects and firing back a local redirect
240 * The feature is conditionally compiled, i.e. it
241 * can be disabled with --disable-fast-redirects,
242 * plus it must be activated by a "fast-redirects"
243 * line in the config file, has its own log level
244 * and of course wants to be displayed by show-proxy-args
245 * Note: Boy, all the #ifdefs in 1001 locations and
246 * all the fumbling with configure.in and acconfig.h
247 * were *way* more work than the feature itself :-(
249 * - Because a generic redirect template was needed for
250 * this, tinygif = 3 now uses the same.
252 * - Moved GIFs, and other static HTTP response templates
257 * - Removed some >400 CRs again (Jon, you really worked
260 * Revision 1.4 2001/05/21 19:32:54 jongfoster
261 * Added another #ifdef _WIN_CONSOLE
263 * Revision 1.3 2001/05/20 01:11:40 jongfoster
264 * Added support for LOG_LEVEL_FATAL
265 * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE,
266 * and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER
268 * Revision 1.2 2001/05/17 22:42:01 oes
269 * - Cleaned CRLF's from the sources and related files
270 * - Repaired logging for REF and FRC
272 * Revision 1.1.1.1 2001/05/15 13:58:51 oes
273 * Initial import of version 2.9.3 source tree
276 *********************************************************************/
280 #include "miscutil.h"
287 #if defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY)
288 #define USE_NEW_LOG_ERROR
289 /* For gettimeofday() */
290 #include <sys/time.h>
291 #endif /* defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY) */
293 #if !defined(_WIN32) && !defined(__OS2__)
295 #endif /* !defined(_WIN32) && !defined(__OS2__) */
307 #endif /* ndef _WIN_CONSOLE */
308 #endif /* def _WIN32 */
310 #define inline __inline
311 #endif /* def _MSC_VER */
314 #include <sys/socket.h> /* For sock_errno */
323 const char errlog_h_rcs[] = ERRLOG_H_VERSION;
327 * LOG_LEVEL_FATAL cannot be turned off. (There are
328 * some exceptional situations where we need to get a
329 * message to the user).
331 #define LOG_LEVEL_MINIMUM LOG_LEVEL_FATAL
333 /* where to log (default: stderr) */
334 static FILE *logfp = NULL;
336 /* logging detail level. */
337 int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);
339 /* static functions */
340 static void fatal_error(const char * error_message);
342 static char *w32_socket_strerr(int errcode, char *tmp_buf);
345 static char *os2_socket_strerr(int errcode, char *tmp_buf);
348 #ifdef FEATURE_PTHREAD
349 static inline void lock_logfile()
351 pthread_mutex_lock(&log_mutex);
353 static inline void unlock_logfile()
355 pthread_mutex_unlock(&log_mutex);
357 static inline void lock_loginit()
359 pthread_mutex_lock(&log_init_mutex);
361 static inline void unlock_loginit()
363 pthread_mutex_unlock(&log_init_mutex);
365 #else /* ! FEATURE_PTHREAD */
367 * FIXME we need a cross-platform locking mechanism.
368 * The locking/unlocking functions below should be
369 * fleshed out for non-pthread implementations.
371 static inline void lock_logfile() {}
372 static inline void unlock_logfile() {}
373 static inline void lock_loginit() {}
374 static inline void unlock_loginit() {}
377 /*********************************************************************
379 * Function : fatal_error
381 * Description : Displays a fatal error to standard error (or, on
382 * a WIN32 GUI, to a dialog box), and exits
383 * JunkBuster with status code 1.
386 * 1 : error_message = The error message to display.
388 * Returns : Does not return.
390 *********************************************************************/
391 static void fatal_error(const char * error_message)
393 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
394 MessageBox(g_hwndLogFrame, error_message, "Privoxy Error",
395 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
397 /* Cleanup - remove taskbar icon etc. */
400 #else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
401 fputs(error_message, stderr);
402 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
415 /*********************************************************************
417 * Function : init_error_log
419 * Description : Initializes the logging module. Must call before
423 * 1 : prog_name = The program name.
424 * 2 : logfname = The logfile name, or NULL for stderr.
425 * 3 : debuglevel = The debugging level.
429 *********************************************************************/
430 void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
436 /* set the logging detail level */
437 debug = debuglevel | LOG_LEVEL_MINIMUM;
439 if ((logfp != NULL) && (logfp != stderr))
441 log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
450 /* set the designated log file */
453 if( NULL == (fp = fopen(logfname, "a")) )
455 log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: %s", logfname);
458 /* set logging to be completely unbuffered */
466 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
467 if (prog_name != NULL)
469 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
474 } /* init_error_log */
476 #if defined(USE_NEW_LOG_ERROR)
478 * Use an alternative log_error version and its helper functions.
480 * The code is mostly copied from the old log_error
481 * function but it's divided into multiple functions,
482 * doesn't use strcpy, strcat or sprintf and compiles
483 * with gcc43 without warnings (on FreeBSD that is).
485 * It should behave like the old log_error function with
488 * - too long format strings are logged truncated instead
489 * of completely replaced with the truncation warning,
490 * - its time stamps contain milliseconds.
493 /*********************************************************************
495 * Function : get_thread_id
497 * Description : Returns a number that is different for each thread.
499 * XXX: Should be moved elsewhere (miscutil.c?)
503 * Returns : thread_id
505 *********************************************************************/
506 long get_thread_id(void)
508 long this_thread = 1; /* was: pthread_t this_thread;*/
512 APIRET ulrc; /* XXX: I have no clue what this does */
515 /* FIXME get current thread id */
516 #ifdef FEATURE_PTHREAD
517 this_thread = (long)pthread_self();
520 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
521 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
522 * pthread_t is supposed to be opaque... but it's fairly random, though, so
523 * we make it mostly presentable.
525 this_thread = abs(this_thread % 1000);
526 #endif /* def __MACH__ */
527 #elif defined(_WIN32)
528 this_thread = GetCurrentThreadId();
529 #elif defined(__OS2__)
530 ulrc = DosGetInfoBlocks(&ptib, NULL);
532 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
533 #endif /* def FEATURE_PTHREAD */
539 /*********************************************************************
541 * Function : get_log_timestamp
543 * Description : Generates the time stamp for the log message prefix.
546 * 1 : buffer = Storage buffer
547 * 2 : buffer_size = Size of storage buffer
549 * Returns : Number of written characters or 0 for error.
551 *********************************************************************/
552 static inline size_t get_log_timestamp(char *buffer, size_t buffer_size)
557 struct timeval tv_now; /* XXX: stupid name */
558 gettimeofday(&tv_now, NULL);
559 long msecs = tv_now.tv_usec / 1000;
560 int msecs_length = 0;
564 #ifdef HAVE_LOCALTIME_R
565 tm_now = *localtime_r(&now, &tm_now);
566 #elif FEATURE_PTHREAD
567 pthread_mutex_lock(&localtime_mutex);
568 tm_now = *localtime(&now);
569 pthread_mutex_unlock(&localtime_mutex);
571 tm_now = *localtime(&now);
574 length = strftime(buffer, buffer_size, "%b %d %H:%M:%S", &tm_now);
577 msecs_length = snprintf(buffer+length, buffer_size - length, ".%.3ld", msecs);
579 if (msecs_length > 0)
581 length += (size_t)msecs_length;
592 /*********************************************************************
594 * Function : get_clf_timestamp
596 * Description : Generates a Common Log Format time string.
599 * 1 : buffer = Storage buffer
600 * 2 : buffer_size = Size of storage buffer
602 * Returns : Number of written characters or 0 for error.
604 *********************************************************************/
605 static inline size_t get_clf_timestamp(char *buffer, size_t buffer_size)
608 * Complex because not all OSs have tm_gmtoff or
609 * the %z field in strftime()
614 #ifdef HAVE_LOCALTIME_R
623 gmt = *gmtime_r(&now, &gmt);
624 #elif FEATURE_PTHREAD
625 pthread_mutex_lock(&gmtime_mutex);
627 pthread_mutex_unlock(&gmtime_mutex);
631 #ifdef HAVE_LOCALTIME_R
632 tm_now = localtime_r(&now, &dummy);
633 #elif FEATURE_PTHREAD
634 pthread_mutex_lock(&localtime_mutex);
635 tm_now = localtime(&now);
636 pthread_mutex_unlock(&localtime_mutex);
638 tm_now = localtime(&now);
640 days = tm_now->tm_yday - gmt.tm_yday;
641 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
642 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
644 length = strftime(buffer, buffer_size, "%d/%b/%Y:%H:%M:%S ", tm_now);
648 tz_length = snprintf(buffer+length, buffer_size-length,
649 "%+03d%02d", mins / 60, abs(mins) % 60);
653 length += (size_t)tz_length;
664 /*********************************************************************
666 * Function : get_log_level_string
668 * Description : Translates a numerical loglevel into a string.
671 * 1 : loglevel = LOG_LEVEL_FOO
673 * Returns : Log level string.
675 *********************************************************************/
676 inline const char *get_log_level_string(int loglevel)
678 char *log_level_string = NULL;
680 assert(0 < loglevel);
684 case LOG_LEVEL_ERROR:
685 log_level_string = "Error";
687 case LOG_LEVEL_FATAL:
688 log_level_string = "Fatal error";
691 log_level_string = "Request";
693 case LOG_LEVEL_CONNECT:
694 log_level_string = "Connect";
697 log_level_string = "Writing";
699 case LOG_LEVEL_HEADER:
700 log_level_string = "Header";
703 log_level_string = "Info";
705 case LOG_LEVEL_RE_FILTER:
706 log_level_string = "Re-Filter";
708 #ifdef FEATURE_FORCE_LOAD
709 case LOG_LEVEL_FORCE:
710 log_level_string = "Force";
712 #endif /* def FEATURE_FORCE_LOAD */
713 #ifdef FEATURE_FAST_REDIRECTS
714 case LOG_LEVEL_REDIRECTS:
715 log_level_string = "Redirect";
717 #endif /* def FEATURE_FAST_REDIRECTS */
718 case LOG_LEVEL_DEANIMATE:
719 log_level_string = "Gif-Deanimate";
721 #ifdef FEATURE_KILL_POPUPS
722 case LOG_LEVEL_POPUPS:
723 log_level_string = "Kill-Popups";
725 #endif /* def FEATURE_KILL_POPUPS */
727 log_level_string = "CGI";
730 log_level_string = "Unknown log level";
733 assert(NULL != log_level_string);
735 return log_level_string;
739 /*********************************************************************
741 * Function : log_error
743 * Description : This is the error-reporting and logging function.
746 * 1 : loglevel = the type of message to be logged
747 * 2 : fmt = the main string we want logged, printf-like
748 * 3 : ... = arguments to be inserted in fmt (printf-like).
752 *********************************************************************/
753 void log_error(int loglevel, const char *fmt, ...)
757 static char *outbuf_save = NULL;
758 char tempbuf[BUFFER_SIZE];
760 const char * src = fmt;
764 * XXX: Make this a config option,
765 * why else do we allocate instead of using
768 size_t log_buffer_size = BUFFER_SIZE;
770 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
772 * Irrespective of debug setting, a GET/POST/CONNECT makes
773 * the taskbar icon animate. (There is an option to disable
774 * this but checking that is handled inside LogShowActivity()).
776 if (loglevel == LOG_LEVEL_GPC)
780 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
782 /* verify if loglevel applies to current settings and bail out if negative */
783 if ((loglevel & debug) == 0)
788 thread_id = get_thread_id();
789 get_log_timestamp(timestamp, sizeof(timestamp));
791 /* protect the whole function because of the static buffer (outbuf) */
794 if (NULL == outbuf_save)
796 outbuf_save = (char*)zalloc(log_buffer_size + 1); /* +1 for paranoia */
797 if (NULL == outbuf_save)
799 snprintf(tempbuf, sizeof(tempbuf),
800 "%s Privoxy(%08lx) Fatal error: log_error() failed to allocate buffer memory.\n"
801 "\nExiting.", timestamp, thread_id);
806 fputs(tempbuf, logfp);
808 fatal_error(tempbuf); /* Exit */
811 outbuf = outbuf_save;
814 * Memsetting the whole buffer to zero (in theory)
815 * makes things easier later on.
817 memset(outbuf, 0, log_buffer_size);
819 /* Add prefix for everything but Common Log Format messages */
820 if (loglevel != LOG_LEVEL_CLF)
822 length = (size_t)snprintf(outbuf, log_buffer_size, "%s Privoxy(%08lx) %s: ",
823 timestamp, thread_id, get_log_level_string(loglevel));
826 /* get ready to scan var. args. */
829 /* build formatted message from fmt and var-args */
830 while ((*src) && (length < log_buffer_size-2))
832 const char *sval = NULL; /* %N string */
833 int ival; /* %N string length or an error code */
834 unsigned uval; /* %u value */
835 long lval; /* %l value */
836 unsigned long ulval; /* %ul value */
838 const char *format_string = tempbuf;
843 outbuf[length++] = ch;
845 * XXX: Only necessary on platforms which don't use pthread
846 * mutexes (mingw32 for example), where multiple threads can
847 * write to the buffer at the same time.
849 outbuf[length] = '\0';
852 outbuf[length] = '\0';
860 ival = va_arg( ap, int );
861 snprintf(tempbuf, sizeof(tempbuf), "%d", ival);
864 uval = va_arg( ap, unsigned );
865 snprintf(tempbuf, sizeof(tempbuf), "%u", uval);
868 /* this is a modifier that must be followed by u or d */
872 lval = va_arg( ap, long );
873 snprintf(tempbuf, sizeof(tempbuf), "%ld", lval);
877 ulval = va_arg( ap, unsigned long );
878 snprintf(tempbuf, sizeof(tempbuf), "%lu", ulval);
882 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
883 loglevel = LOG_LEVEL_FATAL;
888 * Note that char paramaters are converted to int, so we need to
889 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
891 tempbuf[0] = (char) va_arg(ap, int);
895 format_string = va_arg(ap, char *);
896 if (format_string == NULL)
898 format_string = "[null]";
903 * Non-standard: Print a counted unterminated string.
904 * Takes 2 parameters: int length, const char * string.
906 ival = va_arg(ap, int);
907 sval = va_arg(ap, char *);
910 format_string = "[null]";
916 /* That's ok (but stupid) */
922 * That's not ok (and even more stupid)
925 format_string = "[counted string lenght < 0]";
928 else if (ival >= sizeof(tempbuf))
931 * String is too long, copy as much as possible.
932 * It will be further truncated later.
934 memcpy(tempbuf, sval, sizeof(tempbuf)-1);
935 tempbuf[sizeof(tempbuf)-1] = '\0';
939 memcpy(tempbuf, sval, (size_t) ival);
940 tempbuf[ival] = '\0';
944 /* Non-standard: Print error code from errno */
946 ival = WSAGetLastError();
947 format_string = w32_socket_strerr(ival, tempbuf);
952 format_string = os2_socket_strerr(ival, tempbuf);
957 format_string = strerror(ival);
959 #else /* ifndef _WIN32 */
962 format_string = strerror(ival);
963 #else /* ifndef HAVE_STRERROR */
964 format_string = NULL;
965 #endif /* ndef HAVE_STRERROR */
968 snprintf(tempbuf, sizeof(tempbuf), "(errno = %d)", ival);
970 #endif /* ndef _WIN32 */
973 /* Non-standard: Print a Common Log File timestamp */
974 get_clf_timestamp(tempbuf, sizeof(tempbuf));
977 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
978 loglevel = LOG_LEVEL_FATAL;
982 assert(length < log_buffer_size);
983 length += strlcpy(outbuf + length, format_string, log_buffer_size - length);
985 if (length >= log_buffer_size-2)
987 static char warning[] = "... [too long, truncated]";
989 length = log_buffer_size - sizeof(warning) - 1;
990 length += strlcpy(outbuf + length, warning, log_buffer_size - length);
991 assert(length < log_buffer_size);
997 /* done with var. args */
1000 assert(length < log_buffer_size);
1001 length += strlcpy(outbuf + length, "\n", log_buffer_size - length);
1003 /* Some sanity checks */
1004 if (!(length < log_buffer_size)
1005 || !(outbuf[log_buffer_size-1] == '\0')
1006 || !(outbuf[log_buffer_size] == '\0')
1009 /* Repeat as assertions */
1010 assert(length < log_buffer_size);
1011 assert(outbuf[log_buffer_size-1] == '\0');
1013 * outbuf's real size is log_buffer_size+1,
1014 * so while this looks like an off-by-one,
1015 * we're only checking our paranoia byte.
1017 assert(outbuf[log_buffer_size] == '\0');
1019 snprintf(outbuf, log_buffer_size,
1020 "%s Privoxy(%08lx) Fatal error: log_error()'s sanity checks failed. length: %d\n"
1021 "Exiting.", timestamp, thread_id, (int)length);
1022 loglevel = LOG_LEVEL_FATAL;
1025 /* deal with glibc stupidity - it won't let you initialize logfp */
1026 /* XXX: Still necessary? */
1032 fputs(outbuf_save, logfp);
1034 if (loglevel == LOG_LEVEL_FATAL)
1036 fatal_error(outbuf_save);
1037 /* Never get here */
1042 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1043 /* Write to display */
1044 LogPutString(outbuf_save);
1045 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1049 #else /* use traditional log_error version */
1051 /*********************************************************************
1053 * Function : log_error
1055 * Description : This is the error-reporting and logging function.
1058 * 1 : loglevel = the type of message to be logged
1059 * 2 : fmt = the main string we want logged, printf-like
1060 * 3 : ... = arguments to be inserted in fmt (printf-like).
1064 *********************************************************************/
1065 void log_error(int loglevel, const char *fmt, ...)
1069 static char *outbuf_save = NULL;
1070 const char * src = fmt;
1072 long this_thread = 1; /* was: pthread_t this_thread;*/
1076 #endif /* __OS2__ */
1078 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1080 * Irrespective of debug setting, a GET/POST/CONNECT makes
1081 * the taskbar icon animate. (There is an option to disable
1082 * this but checking that is handled inside LogShowActivity()).
1084 if (loglevel == LOG_LEVEL_GPC)
1088 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1090 /* verify if loglevel applies to current settings and bail out if negative */
1091 if ((loglevel & debug) == 0)
1096 /* protect the whole function because of the static buffer (outbuf) */
1099 /* FIXME get current thread id */
1100 #ifdef FEATURE_PTHREAD
1101 this_thread = (long)pthread_self();
1104 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
1105 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
1106 * pthread_t is supposed to be opaque... but it's fairly random, though, so
1107 * we make it mostly presentable.
1109 this_thread = abs(this_thread % 1000);
1110 #endif /* def __MACH__ */
1111 #elif defined(_WIN32)
1112 this_thread = GetCurrentThreadId();
1113 #elif defined(__OS2__)
1114 ulrc = DosGetInfoBlocks(&ptib, NULL);
1116 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
1117 #endif /* def FEATURE_PTHREAD */
1121 outbuf_save = outbuf = (char*)malloc(BUFFER_SIZE);
1122 if (NULL == outbuf_save)
1124 fatal_error("Privoxy failed to allocate log buffer.");
1127 outbuf = outbuf_save;
1131 * Write timestamp into tempbuf.
1133 * Complex because not all OSs have tm_gmtoff or
1134 * the %z field in strftime()
1139 #ifdef HAVE_LOCALTIME_R
1140 tm_now = *localtime_r(&now, &tm_now);
1141 #elif FEATURE_PTHREAD
1142 pthread_mutex_lock(&localtime_mutex);
1143 tm_now = *localtime (&now);
1144 pthread_mutex_unlock(&localtime_mutex);
1146 tm_now = *localtime (&now);
1148 strftime(outbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
1149 outbuf += strlen( outbuf );
1153 case LOG_LEVEL_ERROR:
1154 outc = sprintf(outbuf, "Privoxy(%08lx) Error: ", this_thread);
1156 case LOG_LEVEL_FATAL:
1157 outc = sprintf(outbuf, "Privoxy(%08lx) Fatal error: ", this_thread);
1160 outc = sprintf(outbuf, "Privoxy(%08lx) Request: ", this_thread);
1162 case LOG_LEVEL_CONNECT:
1163 outc = sprintf(outbuf, "Privoxy(%08lx) Connect: ", this_thread);
1166 outc = sprintf(outbuf, "Privoxy(%08lx) Writing: ", this_thread);
1168 case LOG_LEVEL_HEADER:
1169 outc = sprintf(outbuf, "Privoxy(%08lx) Header: ", this_thread);
1171 case LOG_LEVEL_INFO:
1172 outc = sprintf(outbuf, "Privoxy(%08lx) Info: ", this_thread);
1174 case LOG_LEVEL_RE_FILTER:
1175 outc = sprintf(outbuf, "Privoxy(%08lx) Re-Filter: ", this_thread);
1177 #ifdef FEATURE_FORCE_LOAD
1178 case LOG_LEVEL_FORCE:
1179 outc = sprintf(outbuf, "Privoxy(%08lx) Force: ", this_thread);
1181 #endif /* def FEATURE_FORCE_LOAD */
1182 #ifdef FEATURE_FAST_REDIRECTS
1183 case LOG_LEVEL_REDIRECTS:
1184 outc = sprintf(outbuf, "Privoxy(%08lx) Redirect: ", this_thread);
1186 #endif /* def FEATURE_FAST_REDIRECTS */
1187 case LOG_LEVEL_DEANIMATE:
1188 outc = sprintf(outbuf, "Privoxy(%08lx) Gif-Deanimate: ", this_thread);
1191 outbuf = outbuf_save;
1195 #ifdef FEATURE_KILL_POPUPS
1196 case LOG_LEVEL_POPUPS:
1197 outc = sprintf(outbuf, "Privoxy(%08lx) Kill-Popups: ", this_thread);
1199 #endif /* def FEATURE_KILL_POPUPS */
1201 outc = sprintf(outbuf, "Privoxy(%08lx) CGI: ", this_thread);
1204 outc = sprintf(outbuf, "Privoxy(%08lx) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
1208 /* get ready to scan var. args. */
1209 va_start( ap, fmt );
1211 /* build formatted message from fmt and var-args */
1212 while ((*src) && (outc < BUFFER_SIZE-2))
1214 char tempbuf[BUFFER_SIZE];
1219 unsigned long ulval;
1226 outbuf[outc++] = ch;
1233 outbuf[outc++] = '%';
1236 ival = va_arg( ap, int );
1238 outc += sprintf(tempbuf, "%d", ival);
1239 if (outc < BUFFER_SIZE-1)
1241 strcpy(outbuf + oldoutc, tempbuf);
1245 outbuf[oldoutc] = '\0';
1249 uval = va_arg( ap, unsigned );
1251 outc += sprintf(tempbuf, "%u", uval);
1252 if (outc < BUFFER_SIZE-1)
1254 strcpy(outbuf + oldoutc, tempbuf);
1258 outbuf[oldoutc] = '\0';
1262 /* this is a modifier that must be followed by u or d */
1266 lval = va_arg( ap, long );
1268 outc += sprintf(tempbuf, "%ld", lval);
1272 ulval = va_arg( ap, unsigned long );
1274 outc += sprintf(tempbuf, "%lu", ulval);
1279 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1281 "Exiting.", this_thread, fmt);
1286 fputs(outbuf, logfp);
1287 fatal_error(outbuf);
1288 /* Never get here */
1291 if (outc < BUFFER_SIZE-1)
1293 strcpy(outbuf + oldoutc, tempbuf);
1297 outbuf[oldoutc] = '\0';
1302 * Note that char paramaters are converted to int, so we need to
1303 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
1305 outbuf[outc++] = (char) va_arg( ap, int );
1308 sval = va_arg( ap, char * );
1314 outc += strlen(sval);
1315 if (outc < BUFFER_SIZE-1)
1317 strcpy(outbuf + oldoutc, sval);
1321 outbuf[oldoutc] = '\0';
1325 /* Non-standard: Print a counted string. Takes 2 parameters:
1326 * int length, const char * string
1328 ival = va_arg( ap, int );
1329 sval = va_arg( ap, char * );
1340 if (outc < BUFFER_SIZE-1)
1342 memcpy(outbuf + oldoutc, sval, (size_t) ival);
1346 outbuf[oldoutc] = '\0';
1350 /* Non-standard: Print error code from errno */
1352 ival = WSAGetLastError();
1353 sval = w32_socket_strerr(ival, tempbuf);
1355 ival = sock_errno();
1357 sval = os2_socket_strerr(ival, tempbuf);
1361 sval = strerror(ival);
1363 #else /* ifndef _WIN32 */
1365 #ifdef HAVE_STRERROR
1366 sval = strerror(ival);
1367 #else /* ifndef HAVE_STRERROR */
1369 #endif /* ndef HAVE_STRERROR */
1372 sprintf(tempbuf, "(errno = %d)", ival);
1375 #endif /* ndef _WIN32 */
1377 outc += strlen(sval);
1378 if (outc < BUFFER_SIZE-1)
1380 strcpy(outbuf + oldoutc, sval);
1384 outbuf[oldoutc] = '\0';
1388 /* Non-standard: Print a Common Log File timestamp */
1391 * Write timestamp into tempbuf.
1393 * Complex because not all OSs have tm_gmtoff or
1394 * the %z field in strftime()
1399 #ifdef HAVE_LOCALTIME_R
1402 int days, hrs, mins;
1404 #ifdef HAVE_GMTIME_R
1405 gmt = *gmtime_r(&now, &gmt);
1406 #elif FEATURE_PTHREAD
1407 pthread_mutex_lock(&gmtime_mutex);
1408 gmt = *gmtime(&now);
1409 pthread_mutex_unlock(&gmtime_mutex);
1411 gmt = *gmtime(&now);
1413 #ifdef HAVE_LOCALTIME_R
1414 tm_now = localtime_r(&now, &dummy);
1415 #elif FEATURE_PTHREAD
1416 pthread_mutex_lock(&localtime_mutex);
1417 tm_now = localtime (&now);
1418 pthread_mutex_unlock(&localtime_mutex);
1420 tm_now = localtime (&now);
1422 days = tm_now->tm_yday - gmt.tm_yday;
1423 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
1424 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
1425 strftime (tempbuf, BUFFER_SIZE-6, "%d/%b/%Y:%H:%M:%S ", tm_now);
1426 sprintf (tempbuf + strlen(tempbuf), "%+03d%02d", mins / 60, abs(mins) % 60);
1429 outc += strlen(tempbuf);
1430 if (outc < BUFFER_SIZE-1)
1432 strcpy(outbuf + oldoutc, tempbuf);
1436 outbuf[oldoutc] = '\0';
1440 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1442 "Exiting.", this_thread, fmt);
1447 fputs(outbuf_save, logfp);
1449 fatal_error(outbuf_save);
1450 /* Never get here */
1455 } /* for( p ... ) */
1457 /* done with var. args */
1460 if (outc >= BUFFER_SIZE-2)
1462 /* insufficient room for newline and trailing null. */
1464 static const char warning[] = "... [too long, truncated]\n";
1466 if (outc < BUFFER_SIZE)
1468 /* Need to add terminating null in this case. */
1469 outbuf[outc] = '\0';
1472 /* Truncate output */
1473 outbuf[BUFFER_SIZE - sizeof(warning)] = '\0';
1475 /* Append warning */
1476 strcat(outbuf, warning);
1480 /* Add terminating newline and null */
1481 outbuf[outc++] = '\n';
1482 outbuf[outc] = '\0';
1485 /* deal with glibc stupidity - it won't let you initialize logfp */
1491 fputs(outbuf_save, logfp);
1493 if (loglevel == LOG_LEVEL_FATAL)
1495 fatal_error(outbuf_save);
1496 /* Never get here */
1501 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1502 /* Write to display */
1503 LogPutString(outbuf_save);
1504 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1507 #endif /* defined(USE_NEW_LOG_ERROR) */
1511 /*********************************************************************
1513 * Function : w32_socket_strerr
1515 * Description : Translate the return value from WSAGetLastError()
1519 * 1 : errcode = The return value from WSAGetLastError().
1520 * 2 : tmp_buf = A temporary buffer that might be used to
1523 * Returns : String representing the error code. This may be
1524 * a global string constant or a string stored in
1527 *********************************************************************/
1528 static char *w32_socket_strerr(int errcode, char *tmp_buf)
1530 #define TEXT_FOR_ERROR(code,text) \
1531 if (errcode == code) \
1533 return #code " - " text; \
1536 TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
1537 TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
1538 TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
1539 TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
1540 TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
1541 TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
1542 TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
1543 TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
1544 TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
1545 TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
1546 TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
1547 TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
1548 TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
1549 TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
1550 TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
1551 TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
1552 TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
1553 TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
1554 TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
1555 TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
1556 TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
1557 TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
1558 TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
1559 TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
1560 TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
1561 TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
1562 TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
1563 TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
1564 TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
1565 TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
1566 TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
1567 TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
1568 TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
1569 TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
1570 TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
1571 TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
1572 TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
1573 TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
1574 TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
1575 TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
1576 TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
1577 TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
1579 * The following error codes are documented in the Microsoft WinSock
1580 * reference guide, but don't actually exist.
1582 * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
1583 * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
1584 * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
1585 * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
1586 * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
1587 * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
1588 * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
1589 * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
1590 * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
1591 * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
1594 sprintf(tmp_buf, "(error number %d)", errcode);
1597 #endif /* def _WIN32 */
1601 /*********************************************************************
1603 * Function : os2_socket_strerr
1605 * Description : Translate the return value from sock_errno()
1609 * 1 : errcode = The return value from sock_errno().
1610 * 2 : tmp_buf = A temporary buffer that might be used to
1613 * Returns : String representing the error code. This may be
1614 * a global string constant or a string stored in
1617 *********************************************************************/
1618 static char *os2_socket_strerr(int errcode, char *tmp_buf)
1620 #define TEXT_FOR_ERROR(code,text) \
1621 if (errcode == code) \
1623 return #code " - " text; \
1626 TEXT_FOR_ERROR(SOCEPERM , "Not owner.")
1627 TEXT_FOR_ERROR(SOCESRCH , "No such process.")
1628 TEXT_FOR_ERROR(SOCEINTR , "Interrupted system call.")
1629 TEXT_FOR_ERROR(SOCENXIO , "No such device or address.")
1630 TEXT_FOR_ERROR(SOCEBADF , "Bad file number.")
1631 TEXT_FOR_ERROR(SOCEACCES , "Permission denied.")
1632 TEXT_FOR_ERROR(SOCEFAULT , "Bad address.")
1633 TEXT_FOR_ERROR(SOCEINVAL , "Invalid argument.")
1634 TEXT_FOR_ERROR(SOCEMFILE , "Too many open files.")
1635 TEXT_FOR_ERROR(SOCEPIPE , "Broken pipe.")
1636 TEXT_FOR_ERROR(SOCEWOULDBLOCK , "Operation would block.")
1637 TEXT_FOR_ERROR(SOCEINPROGRESS , "Operation now in progress.")
1638 TEXT_FOR_ERROR(SOCEALREADY , "Operation already in progress.")
1639 TEXT_FOR_ERROR(SOCENOTSOCK , "Socket operation on non-socket.")
1640 TEXT_FOR_ERROR(SOCEDESTADDRREQ , "Destination address required.")
1641 TEXT_FOR_ERROR(SOCEMSGSIZE , "Message too long.")
1642 TEXT_FOR_ERROR(SOCEPROTOTYPE , "Protocol wrong type for socket.")
1643 TEXT_FOR_ERROR(SOCENOPROTOOPT , "Protocol not available.")
1644 TEXT_FOR_ERROR(SOCEPROTONOSUPPORT, "Protocol not supported.")
1645 TEXT_FOR_ERROR(SOCESOCKTNOSUPPORT, "Socket type not supported.")
1646 TEXT_FOR_ERROR(SOCEOPNOTSUPP , "Operation not supported.")
1647 TEXT_FOR_ERROR(SOCEPFNOSUPPORT , "Protocol family not supported.")
1648 TEXT_FOR_ERROR(SOCEAFNOSUPPORT , "Address family not supported by protocol family.")
1649 TEXT_FOR_ERROR(SOCEADDRINUSE , "Address already in use.")
1650 TEXT_FOR_ERROR(SOCEADDRNOTAVAIL , "Can't assign requested address.")
1651 TEXT_FOR_ERROR(SOCENETDOWN , "Network is down.")
1652 TEXT_FOR_ERROR(SOCENETUNREACH , "Network is unreachable.")
1653 TEXT_FOR_ERROR(SOCENETRESET , "Network dropped connection on reset.")
1654 TEXT_FOR_ERROR(SOCECONNABORTED , "Software caused connection abort.")
1655 TEXT_FOR_ERROR(SOCECONNRESET , "Connection reset by peer.")
1656 TEXT_FOR_ERROR(SOCENOBUFS , "No buffer space available.")
1657 TEXT_FOR_ERROR(SOCEISCONN , "Socket is already connected.")
1658 TEXT_FOR_ERROR(SOCENOTCONN , "Socket is not connected.")
1659 TEXT_FOR_ERROR(SOCESHUTDOWN , "Can't send after socket shutdown.")
1660 TEXT_FOR_ERROR(SOCETOOMANYREFS , "Too many references: can't splice.")
1661 TEXT_FOR_ERROR(SOCETIMEDOUT , "Operation timed out.")
1662 TEXT_FOR_ERROR(SOCECONNREFUSED , "Connection refused.")
1663 TEXT_FOR_ERROR(SOCELOOP , "Too many levels of symbolic links.")
1664 TEXT_FOR_ERROR(SOCENAMETOOLONG , "File name too long.")
1665 TEXT_FOR_ERROR(SOCEHOSTDOWN , "Host is down.")
1666 TEXT_FOR_ERROR(SOCEHOSTUNREACH , "No route to host.")
1667 TEXT_FOR_ERROR(SOCENOTEMPTY , "Directory not empty.")
1668 TEXT_FOR_ERROR(SOCEOS2ERR , "OS/2 Error.")
1670 sprintf(tmp_buf, "(error number %d)", errcode);
1673 #endif /* def __OS2__ */