1 const char errlog_rcs[] = "$Id: errlog.c,v 1.52 2007/07/14 07:28:47 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.52 2007/07/14 07:28:47 fabiankeil
37 * Add translation function for JB_ERR_FOO codes.
39 * Revision 1.51 2007/05/11 11:51:34 fabiankeil
40 * Fix a type mismatch warning.
42 * Revision 1.50 2007/04/11 10:55:44 fabiankeil
43 * Enforce some assertions that could be triggered
44 * on mingw32 and other systems where we use threads
47 * Revision 1.49 2007/04/08 16:44:15 fabiankeil
48 * We need <sys/time.h> for gettimeofday(), not <time.h>.
50 * Revision 1.48 2007/03/31 13:33:28 fabiankeil
51 * Add alternative log_error() with timestamps
52 * that contain milliseconds and without using
53 * strcpy(), strcat() or sprintf().
55 * Revision 1.47 2006/11/28 15:25:15 fabiankeil
56 * Only unlink the pidfile if it's actually used.
58 * Revision 1.46 2006/11/13 19:05:51 fabiankeil
59 * Make pthread mutex locking more generic. Instead of
60 * checking for OSX and OpenBSD, check for FEATURE_PTHREAD
61 * and use mutex locking unless there is an _r function
62 * available. Better safe than sorry.
64 * Fixes "./configure --disable-pthread" and should result
65 * in less threading-related problems on pthread-using platforms,
66 * but it still doesn't fix BR#1122404.
68 * Revision 1.45 2006/08/21 11:15:54 david__schmidt
69 * MS Visual C++ build updates
71 * Revision 1.44 2006/08/18 16:03:16 david__schmidt
72 * Tweak for OS/2 build happiness.
74 * Revision 1.43 2006/08/03 02:46:41 david__schmidt
75 * Incorporate Fabian Keil's patch work:
76 * http://www.fabiankeil.de/sourcecode/privoxy/
78 * Revision 1.42 2006/07/18 14:48:46 david__schmidt
79 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
80 * with what was really the latest development (the v_3_0_branch branch)
82 * Revision 1.40.2.4 2005/04/03 20:10:50 david__schmidt
83 * Thanks to Jindrich Makovicka for a race condition fix for the log
84 * file. The race condition remains for non-pthread implementations.
85 * Reference patch #1175720.
87 * Revision 1.40.2.3 2003/03/07 03:41:04 david__schmidt
88 * Wrapping all *_r functions (the non-_r versions of them) with mutex
89 * semaphores for OSX. Hopefully this will take care of all of those pesky
92 * Revision 1.40.2.2 2002/09/28 00:30:57 david__schmidt
93 * Update error logging to give sane values for thread IDs on Mach kernels.
94 * It's still a hack, but at least it looks farily normal. We print the
95 * absolute value of the first 4 bytes of the pthread_t modded with 1000.
97 * Revision 1.40.2.1 2002/09/25 12:47:42 oes
98 * Make log_error safe against NULL string arguments
100 * Revision 1.40 2002/05/22 01:27:27 david__schmidt
102 * Add os2_socket_strerr mirroring w32_socket_strerr.
104 * Revision 1.39 2002/04/03 17:15:27 gliptak
105 * zero padding thread ids in log
107 * Revision 1.38 2002/03/31 17:18:59 jongfoster
108 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
110 * Revision 1.37 2002/03/27 14:32:43 david__schmidt
111 * More compiler warning message maintenance
113 * Revision 1.36 2002/03/26 22:29:54 swa
114 * we have a new homepage!
116 * Revision 1.35 2002/03/24 15:23:33 jongfoster
119 * Revision 1.34 2002/03/24 13:25:43 swa
120 * name change related issues
122 * Revision 1.33 2002/03/13 00:27:04 jongfoster
125 * Revision 1.32 2002/03/07 03:46:17 oes
126 * Fixed compiler warnings
128 * Revision 1.31 2002/03/06 23:02:57 jongfoster
131 * Revision 1.30 2002/03/05 22:43:45 david__schmidt
132 * - Better error reporting on OS/2
133 * - Fix double-slash comment (oops)
135 * Revision 1.29 2002/03/04 23:45:13 jongfoster
136 * Printing thread ID if using Win32 native threads
138 * Revision 1.28 2002/03/04 17:59:59 oes
139 * Deleted deletePidFile(), cosmetics
141 * Revision 1.27 2002/03/04 02:08:01 david__schmidt
142 * Enable web editing of actions file on OS/2 (it had been broken all this time!)
144 * Revision 1.26 2002/01/09 19:05:45 steudten
145 * Fix big memory leak.
147 * Revision 1.25 2002/01/09 14:32:08 oes
148 * Added support for gmtime_r and localtime_r.
150 * Revision 1.24 2001/12/30 14:07:32 steudten
151 * - Add signal handling (unix)
152 * - Add SIGHUP handler (unix)
153 * - Add creation of pidfile (unix)
154 * - Add action 'top' in rc file (RH)
155 * - Add entry 'SIGNALS' to manpage
156 * - Add exit message to logfile (unix)
158 * Revision 1.23 2001/11/07 00:02:13 steudten
159 * Add line number in error output for lineparsing for
160 * actionsfile and configfile.
161 * Special handling for CLF added.
163 * Revision 1.22 2001/11/05 23:43:05 steudten
164 * Add time+date to log files.
166 * Revision 1.21 2001/10/25 03:40:47 david__schmidt
167 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
168 * threads to call select() simultaneously. So, it's time to do a real, live,
169 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
170 * (native). Both versions will work, but using __OS2__ offers multi-threading.
172 * Revision 1.20 2001/09/16 23:04:34 jongfoster
175 * Revision 1.19 2001/09/13 20:08:06 jongfoster
176 * Adding support for LOG_LEVEL_CGI
178 * Revision 1.18 2001/09/10 11:27:24 oes
179 * Declaration of w32_socket_strerr now conditional
181 * Revision 1.17 2001/09/10 10:17:13 oes
182 * Removed unused variable; Fixed sprintf format
184 * Revision 1.16 2001/07/30 22:08:36 jongfoster
185 * Tidying up #defines:
186 * - All feature #defines are now of the form FEATURE_xxx
187 * - Permanently turned off WIN_GUI_EDIT
188 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
190 * Revision 1.15 2001/07/29 17:41:10 jongfoster
191 * Now prints thread ID for each message (pthreads only)
193 * Revision 1.14 2001/07/19 19:03:48 haroon
194 * - Added case for LOG_LEVEL_POPUPS
196 * Revision 1.13 2001/07/13 13:58:58 oes
197 * - Added case for LOG_LEVEL_DEANIMATE
198 * - Removed all #ifdef PCRS
200 * Revision 1.12 2001/06/09 10:55:28 jongfoster
201 * Changing BUFSIZ ==> BUFFER_SIZE
203 * Revision 1.11 2001/06/01 18:14:49 jongfoster
204 * Changing the calls to strerr() to check HAVE_STRERR (which is defined
205 * in config.h if appropriate) rather than the NO_STRERR macro.
207 * Revision 1.10 2001/05/29 11:52:21 oes
208 * Conditional compilation of w32_socket_error
210 * Revision 1.9 2001/05/28 16:15:17 jongfoster
211 * Improved reporting of errors under Win32.
213 * Revision 1.8 2001/05/26 17:25:14 jongfoster
214 * Added support for CLF (Common Log Format) and fixed LOG_LEVEL_LOG
216 * Revision 1.7 2001/05/26 15:21:28 jongfoster
217 * Activity animation in Win32 GUI now works even if debug==0
219 * Revision 1.6 2001/05/25 21:55:08 jongfoster
220 * Now cleans up properly on FATAL (removes taskbar icon etc)
222 * Revision 1.5 2001/05/22 18:46:04 oes
224 * - Enabled filtering banners by size rather than URL
225 * by adding patterns that replace all standard banner
226 * sizes with the "Junkbuster" gif to the re_filterfile
228 * - Enabled filtering WebBugs by providing a pattern
229 * which kills all 1x1 images
231 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
232 * which is selected by the (nonstandard and therefore
233 * capital) letter 'U' in the option string.
234 * It causes the quantifiers to be ungreedy by default.
235 * Appending a ? turns back to greedy (!).
237 * - Added a new interceptor ijb-send-banner, which
238 * sends back the "Junkbuster" gif. Without imagelist or
239 * MSIE detection support, or if tinygif = 1, or the
240 * URL isn't recognized as an imageurl, a lame HTML
241 * explanation is sent instead.
243 * - Added new feature, which permits blocking remote
244 * script redirects and firing back a local redirect
246 * The feature is conditionally compiled, i.e. it
247 * can be disabled with --disable-fast-redirects,
248 * plus it must be activated by a "fast-redirects"
249 * line in the config file, has its own log level
250 * and of course wants to be displayed by show-proxy-args
251 * Note: Boy, all the #ifdefs in 1001 locations and
252 * all the fumbling with configure.in and acconfig.h
253 * were *way* more work than the feature itself :-(
255 * - Because a generic redirect template was needed for
256 * this, tinygif = 3 now uses the same.
258 * - Moved GIFs, and other static HTTP response templates
263 * - Removed some >400 CRs again (Jon, you really worked
266 * Revision 1.4 2001/05/21 19:32:54 jongfoster
267 * Added another #ifdef _WIN_CONSOLE
269 * Revision 1.3 2001/05/20 01:11:40 jongfoster
270 * Added support for LOG_LEVEL_FATAL
271 * Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE,
272 * and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER
274 * Revision 1.2 2001/05/17 22:42:01 oes
275 * - Cleaned CRLF's from the sources and related files
276 * - Repaired logging for REF and FRC
278 * Revision 1.1.1.1 2001/05/15 13:58:51 oes
279 * Initial import of version 2.9.3 source tree
282 *********************************************************************/
286 #include "miscutil.h"
293 #if defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY)
294 #define USE_NEW_LOG_ERROR
295 /* For gettimeofday() */
296 #include <sys/time.h>
297 #endif /* defined(HAVE_STRLCPY) && defined(HAVE_GETTIMEOFDAY) */
299 #if !defined(_WIN32) && !defined(__OS2__)
301 #endif /* !defined(_WIN32) && !defined(__OS2__) */
313 #endif /* ndef _WIN_CONSOLE */
314 #endif /* def _WIN32 */
316 #define inline __inline
317 #endif /* def _MSC_VER */
320 #include <sys/socket.h> /* For sock_errno */
329 const char errlog_h_rcs[] = ERRLOG_H_VERSION;
333 * LOG_LEVEL_FATAL cannot be turned off. (There are
334 * some exceptional situations where we need to get a
335 * message to the user).
337 #define LOG_LEVEL_MINIMUM LOG_LEVEL_FATAL
339 /* where to log (default: stderr) */
340 static FILE *logfp = NULL;
342 /* logging detail level. */
343 int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);
345 /* static functions */
346 static void fatal_error(const char * error_message);
348 static char *w32_socket_strerr(int errcode, char *tmp_buf);
351 static char *os2_socket_strerr(int errcode, char *tmp_buf);
354 #ifdef FEATURE_PTHREAD
355 static inline void lock_logfile(void)
357 pthread_mutex_lock(&log_mutex);
359 static inline void unlock_logfile(void)
361 pthread_mutex_unlock(&log_mutex);
363 static inline void lock_loginit(void)
365 pthread_mutex_lock(&log_init_mutex);
367 static inline void unlock_loginit(void)
369 pthread_mutex_unlock(&log_init_mutex);
371 #else /* ! FEATURE_PTHREAD */
373 * FIXME we need a cross-platform locking mechanism.
374 * The locking/unlocking functions below should be
375 * fleshed out for non-pthread implementations.
377 static inline void lock_logfile() {}
378 static inline void unlock_logfile() {}
379 static inline void lock_loginit() {}
380 static inline void unlock_loginit() {}
383 /*********************************************************************
385 * Function : fatal_error
387 * Description : Displays a fatal error to standard error (or, on
388 * a WIN32 GUI, to a dialog box), and exits
389 * JunkBuster with status code 1.
392 * 1 : error_message = The error message to display.
394 * Returns : Does not return.
396 *********************************************************************/
397 static void fatal_error(const char * error_message)
399 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
400 MessageBox(g_hwndLogFrame, error_message, "Privoxy Error",
401 MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
403 /* Cleanup - remove taskbar icon etc. */
406 #else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
407 fputs(error_message, stderr);
408 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
421 /*********************************************************************
423 * Function : init_error_log
425 * Description : Initializes the logging module. Must call before
429 * 1 : prog_name = The program name.
430 * 2 : logfname = The logfile name, or NULL for stderr.
431 * 3 : debuglevel = The debugging level.
435 *********************************************************************/
436 void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
442 /* set the logging detail level */
443 debug = debuglevel | LOG_LEVEL_MINIMUM;
445 if ((logfp != NULL) && (logfp != stderr))
447 log_error(LOG_LEVEL_INFO, "(Re-)Open logfile %s", logfname ? logfname : "none");
456 /* set the designated log file */
459 if( NULL == (fp = fopen(logfname, "a")) )
461 log_error(LOG_LEVEL_FATAL, "init_error_log(): can't open logfile: %s", logfname);
464 /* set logging to be completely unbuffered */
472 log_error(LOG_LEVEL_INFO, "Privoxy version " VERSION);
473 if (prog_name != NULL)
475 log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
480 } /* init_error_log */
482 #if defined(USE_NEW_LOG_ERROR)
484 * Use an alternative log_error version and its helper functions.
486 * The code is mostly copied from the old log_error
487 * function but it's divided into multiple functions,
488 * doesn't use strcpy, strcat or sprintf and compiles
489 * with gcc43 without warnings (on FreeBSD that is).
491 * It should behave like the old log_error function with
494 * - too long format strings are logged truncated instead
495 * of completely replaced with the truncation warning,
496 * - its time stamps contain milliseconds.
499 /*********************************************************************
501 * Function : get_thread_id
503 * Description : Returns a number that is different for each thread.
505 * XXX: Should be moved elsewhere (miscutil.c?)
509 * Returns : thread_id
511 *********************************************************************/
512 static long get_thread_id(void)
514 long this_thread = 1; /* was: pthread_t this_thread;*/
518 APIRET ulrc; /* XXX: I have no clue what this does */
521 /* FIXME get current thread id */
522 #ifdef FEATURE_PTHREAD
523 this_thread = (long)pthread_self();
526 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
527 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
528 * pthread_t is supposed to be opaque... but it's fairly random, though, so
529 * we make it mostly presentable.
531 this_thread = abs(this_thread % 1000);
532 #endif /* def __MACH__ */
533 #elif defined(_WIN32)
534 this_thread = GetCurrentThreadId();
535 #elif defined(__OS2__)
536 ulrc = DosGetInfoBlocks(&ptib, NULL);
538 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
539 #endif /* def FEATURE_PTHREAD */
545 /*********************************************************************
547 * Function : get_log_timestamp
549 * Description : Generates the time stamp for the log message prefix.
552 * 1 : buffer = Storage buffer
553 * 2 : buffer_size = Size of storage buffer
555 * Returns : Number of written characters or 0 for error.
557 *********************************************************************/
558 static inline size_t get_log_timestamp(char *buffer, size_t buffer_size)
563 struct timeval tv_now; /* XXX: stupid name */
564 gettimeofday(&tv_now, NULL);
565 long msecs = tv_now.tv_usec / 1000;
566 int msecs_length = 0;
570 #ifdef HAVE_LOCALTIME_R
571 tm_now = *localtime_r(&now, &tm_now);
572 #elif FEATURE_PTHREAD
573 pthread_mutex_lock(&localtime_mutex);
574 tm_now = *localtime(&now);
575 pthread_mutex_unlock(&localtime_mutex);
577 tm_now = *localtime(&now);
580 length = strftime(buffer, buffer_size, "%b %d %H:%M:%S", &tm_now);
583 msecs_length = snprintf(buffer+length, buffer_size - length, ".%.3ld", msecs);
585 if (msecs_length > 0)
587 length += (size_t)msecs_length;
598 /*********************************************************************
600 * Function : get_clf_timestamp
602 * Description : Generates a Common Log Format time string.
605 * 1 : buffer = Storage buffer
606 * 2 : buffer_size = Size of storage buffer
608 * Returns : Number of written characters or 0 for error.
610 *********************************************************************/
611 static inline size_t get_clf_timestamp(char *buffer, size_t buffer_size)
614 * Complex because not all OSs have tm_gmtoff or
615 * the %z field in strftime()
620 #ifdef HAVE_LOCALTIME_R
629 gmt = *gmtime_r(&now, &gmt);
630 #elif FEATURE_PTHREAD
631 pthread_mutex_lock(&gmtime_mutex);
633 pthread_mutex_unlock(&gmtime_mutex);
637 #ifdef HAVE_LOCALTIME_R
638 tm_now = localtime_r(&now, &dummy);
639 #elif FEATURE_PTHREAD
640 pthread_mutex_lock(&localtime_mutex);
641 tm_now = localtime(&now);
642 pthread_mutex_unlock(&localtime_mutex);
644 tm_now = localtime(&now);
646 days = tm_now->tm_yday - gmt.tm_yday;
647 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
648 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
650 length = strftime(buffer, buffer_size, "%d/%b/%Y:%H:%M:%S ", tm_now);
654 tz_length = snprintf(buffer+length, buffer_size-length,
655 "%+03d%02d", mins / 60, abs(mins) % 60);
659 length += (size_t)tz_length;
670 /*********************************************************************
672 * Function : get_log_level_string
674 * Description : Translates a numerical loglevel into a string.
677 * 1 : loglevel = LOG_LEVEL_FOO
679 * Returns : Log level string.
681 *********************************************************************/
682 static inline const char *get_log_level_string(int loglevel)
684 char *log_level_string = NULL;
686 assert(0 < loglevel);
690 case LOG_LEVEL_ERROR:
691 log_level_string = "Error";
693 case LOG_LEVEL_FATAL:
694 log_level_string = "Fatal error";
697 log_level_string = "Request";
699 case LOG_LEVEL_CONNECT:
700 log_level_string = "Connect";
703 log_level_string = "Writing";
705 case LOG_LEVEL_HEADER:
706 log_level_string = "Header";
709 log_level_string = "Info";
711 case LOG_LEVEL_RE_FILTER:
712 log_level_string = "Re-Filter";
714 #ifdef FEATURE_FORCE_LOAD
715 case LOG_LEVEL_FORCE:
716 log_level_string = "Force";
718 #endif /* def FEATURE_FORCE_LOAD */
719 #ifdef FEATURE_FAST_REDIRECTS
720 case LOG_LEVEL_REDIRECTS:
721 log_level_string = "Redirect";
723 #endif /* def FEATURE_FAST_REDIRECTS */
724 case LOG_LEVEL_DEANIMATE:
725 log_level_string = "Gif-Deanimate";
727 #ifdef FEATURE_KILL_POPUPS
728 case LOG_LEVEL_POPUPS:
729 log_level_string = "Kill-Popups";
731 #endif /* def FEATURE_KILL_POPUPS */
733 log_level_string = "CGI";
736 log_level_string = "Unknown log level";
739 assert(NULL != log_level_string);
741 return log_level_string;
745 /*********************************************************************
747 * Function : log_error
749 * Description : This is the error-reporting and logging function.
752 * 1 : loglevel = the type of message to be logged
753 * 2 : fmt = the main string we want logged, printf-like
754 * 3 : ... = arguments to be inserted in fmt (printf-like).
758 *********************************************************************/
759 void log_error(int loglevel, const char *fmt, ...)
763 static char *outbuf_save = NULL;
764 char tempbuf[BUFFER_SIZE];
766 const char * src = fmt;
770 * XXX: Make this a config option,
771 * why else do we allocate instead of using
774 size_t log_buffer_size = BUFFER_SIZE;
776 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
778 * Irrespective of debug setting, a GET/POST/CONNECT makes
779 * the taskbar icon animate. (There is an option to disable
780 * this but checking that is handled inside LogShowActivity()).
782 if (loglevel == LOG_LEVEL_GPC)
786 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
788 /* verify if loglevel applies to current settings and bail out if negative */
789 if ((loglevel & debug) == 0)
794 thread_id = get_thread_id();
795 get_log_timestamp(timestamp, sizeof(timestamp));
797 /* protect the whole function because of the static buffer (outbuf) */
800 if (NULL == outbuf_save)
802 outbuf_save = (char*)zalloc(log_buffer_size + 1); /* +1 for paranoia */
803 if (NULL == outbuf_save)
805 snprintf(tempbuf, sizeof(tempbuf),
806 "%s Privoxy(%08lx) Fatal error: log_error() failed to allocate buffer memory.\n"
807 "\nExiting.", timestamp, thread_id);
812 fputs(tempbuf, logfp);
814 fatal_error(tempbuf); /* Exit */
817 outbuf = outbuf_save;
820 * Memsetting the whole buffer to zero (in theory)
821 * makes things easier later on.
823 memset(outbuf, 0, log_buffer_size);
825 /* Add prefix for everything but Common Log Format messages */
826 if (loglevel != LOG_LEVEL_CLF)
828 length = (size_t)snprintf(outbuf, log_buffer_size, "%s Privoxy(%08lx) %s: ",
829 timestamp, thread_id, get_log_level_string(loglevel));
832 /* get ready to scan var. args. */
835 /* build formatted message from fmt and var-args */
836 while ((*src) && (length < log_buffer_size-2))
838 const char *sval = NULL; /* %N string */
839 int ival; /* %N string length or an error code */
840 unsigned uval; /* %u value */
841 long lval; /* %l value */
842 unsigned long ulval; /* %ul value */
844 const char *format_string = tempbuf;
849 outbuf[length++] = ch;
851 * XXX: Only necessary on platforms which don't use pthread
852 * mutexes (mingw32 for example), where multiple threads can
853 * write to the buffer at the same time.
855 outbuf[length] = '\0';
858 outbuf[length] = '\0';
866 ival = va_arg( ap, int );
867 snprintf(tempbuf, sizeof(tempbuf), "%d", ival);
870 uval = va_arg( ap, unsigned );
871 snprintf(tempbuf, sizeof(tempbuf), "%u", uval);
874 /* this is a modifier that must be followed by u or d */
878 lval = va_arg( ap, long );
879 snprintf(tempbuf, sizeof(tempbuf), "%ld", lval);
883 ulval = va_arg( ap, unsigned long );
884 snprintf(tempbuf, sizeof(tempbuf), "%lu", ulval);
888 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
889 loglevel = LOG_LEVEL_FATAL;
894 * Note that char paramaters are converted to int, so we need to
895 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
897 tempbuf[0] = (char) va_arg(ap, int);
901 format_string = va_arg(ap, char *);
902 if (format_string == NULL)
904 format_string = "[null]";
909 * Non-standard: Print a counted unterminated string.
910 * Takes 2 parameters: int length, const char * string.
912 ival = va_arg(ap, int);
913 sval = va_arg(ap, char *);
916 format_string = "[null]";
922 /* That's ok (but stupid) */
928 * That's not ok (and even more stupid)
931 format_string = "[counted string lenght < 0]";
934 else if (ival >= sizeof(tempbuf))
937 * String is too long, copy as much as possible.
938 * It will be further truncated later.
940 memcpy(tempbuf, sval, sizeof(tempbuf)-1);
941 tempbuf[sizeof(tempbuf)-1] = '\0';
945 memcpy(tempbuf, sval, (size_t) ival);
946 tempbuf[ival] = '\0';
950 /* Non-standard: Print error code from errno */
952 ival = WSAGetLastError();
953 format_string = w32_socket_strerr(ival, tempbuf);
958 format_string = os2_socket_strerr(ival, tempbuf);
963 format_string = strerror(ival);
965 #else /* ifndef _WIN32 */
968 format_string = strerror(ival);
969 #else /* ifndef HAVE_STRERROR */
970 format_string = NULL;
971 #endif /* ndef HAVE_STRERROR */
974 snprintf(tempbuf, sizeof(tempbuf), "(errno = %d)", ival);
976 #endif /* ndef _WIN32 */
979 /* Non-standard: Print a Common Log File timestamp */
980 get_clf_timestamp(tempbuf, sizeof(tempbuf));
983 snprintf(tempbuf, sizeof(tempbuf), "Bad format string: \"%s\"", fmt);
984 loglevel = LOG_LEVEL_FATAL;
988 assert(length < log_buffer_size);
989 length += strlcpy(outbuf + length, format_string, log_buffer_size - length);
991 if (length >= log_buffer_size-2)
993 static char warning[] = "... [too long, truncated]";
995 length = log_buffer_size - sizeof(warning) - 1;
996 length += strlcpy(outbuf + length, warning, log_buffer_size - length);
997 assert(length < log_buffer_size);
1001 } /* for( p ... ) */
1003 /* done with var. args */
1006 assert(length < log_buffer_size);
1007 length += strlcpy(outbuf + length, "\n", log_buffer_size - length);
1009 /* Some sanity checks */
1010 if (!(length < log_buffer_size)
1011 || !(outbuf[log_buffer_size-1] == '\0')
1012 || !(outbuf[log_buffer_size] == '\0')
1015 /* Repeat as assertions */
1016 assert(length < log_buffer_size);
1017 assert(outbuf[log_buffer_size-1] == '\0');
1019 * outbuf's real size is log_buffer_size+1,
1020 * so while this looks like an off-by-one,
1021 * we're only checking our paranoia byte.
1023 assert(outbuf[log_buffer_size] == '\0');
1025 snprintf(outbuf, log_buffer_size,
1026 "%s Privoxy(%08lx) Fatal error: log_error()'s sanity checks failed. length: %d\n"
1027 "Exiting.", timestamp, thread_id, (int)length);
1028 loglevel = LOG_LEVEL_FATAL;
1031 /* deal with glibc stupidity - it won't let you initialize logfp */
1032 /* XXX: Still necessary? */
1038 fputs(outbuf_save, logfp);
1040 if (loglevel == LOG_LEVEL_FATAL)
1042 fatal_error(outbuf_save);
1043 /* Never get here */
1048 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1049 /* Write to display */
1050 LogPutString(outbuf_save);
1051 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1055 #else /* use traditional log_error version */
1057 /*********************************************************************
1059 * Function : log_error
1061 * Description : This is the error-reporting and logging function.
1064 * 1 : loglevel = the type of message to be logged
1065 * 2 : fmt = the main string we want logged, printf-like
1066 * 3 : ... = arguments to be inserted in fmt (printf-like).
1070 *********************************************************************/
1071 void log_error(int loglevel, const char *fmt, ...)
1075 static char *outbuf_save = NULL;
1076 const char * src = fmt;
1078 long this_thread = 1; /* was: pthread_t this_thread;*/
1082 #endif /* __OS2__ */
1084 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1086 * Irrespective of debug setting, a GET/POST/CONNECT makes
1087 * the taskbar icon animate. (There is an option to disable
1088 * this but checking that is handled inside LogShowActivity()).
1090 if (loglevel == LOG_LEVEL_GPC)
1094 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1096 /* verify if loglevel applies to current settings and bail out if negative */
1097 if ((loglevel & debug) == 0)
1102 /* protect the whole function because of the static buffer (outbuf) */
1105 /* FIXME get current thread id */
1106 #ifdef FEATURE_PTHREAD
1107 this_thread = (long)pthread_self();
1110 * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable
1111 * value at the first 4 bytes of pthread_self()'s return value, a pthread_t.
1112 * pthread_t is supposed to be opaque... but it's fairly random, though, so
1113 * we make it mostly presentable.
1115 this_thread = abs(this_thread % 1000);
1116 #endif /* def __MACH__ */
1117 #elif defined(_WIN32)
1118 this_thread = GetCurrentThreadId();
1119 #elif defined(__OS2__)
1120 ulrc = DosGetInfoBlocks(&ptib, NULL);
1122 this_thread = ptib -> tib_ptib2 -> tib2_ultid;
1123 #endif /* def FEATURE_PTHREAD */
1127 outbuf_save = outbuf = (char*)malloc(BUFFER_SIZE);
1128 if (NULL == outbuf_save)
1130 fatal_error("Privoxy failed to allocate log buffer.");
1133 outbuf = outbuf_save;
1137 * Write timestamp into tempbuf.
1139 * Complex because not all OSs have tm_gmtoff or
1140 * the %z field in strftime()
1145 #ifdef HAVE_LOCALTIME_R
1146 tm_now = *localtime_r(&now, &tm_now);
1147 #elif FEATURE_PTHREAD
1148 pthread_mutex_lock(&localtime_mutex);
1149 tm_now = *localtime (&now);
1150 pthread_mutex_unlock(&localtime_mutex);
1152 tm_now = *localtime (&now);
1154 strftime(outbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
1155 outbuf += strlen( outbuf );
1159 case LOG_LEVEL_ERROR:
1160 outc = sprintf(outbuf, "Privoxy(%08lx) Error: ", this_thread);
1162 case LOG_LEVEL_FATAL:
1163 outc = sprintf(outbuf, "Privoxy(%08lx) Fatal error: ", this_thread);
1166 outc = sprintf(outbuf, "Privoxy(%08lx) Request: ", this_thread);
1168 case LOG_LEVEL_CONNECT:
1169 outc = sprintf(outbuf, "Privoxy(%08lx) Connect: ", this_thread);
1172 outc = sprintf(outbuf, "Privoxy(%08lx) Writing: ", this_thread);
1174 case LOG_LEVEL_HEADER:
1175 outc = sprintf(outbuf, "Privoxy(%08lx) Header: ", this_thread);
1177 case LOG_LEVEL_INFO:
1178 outc = sprintf(outbuf, "Privoxy(%08lx) Info: ", this_thread);
1180 case LOG_LEVEL_RE_FILTER:
1181 outc = sprintf(outbuf, "Privoxy(%08lx) Re-Filter: ", this_thread);
1183 #ifdef FEATURE_FORCE_LOAD
1184 case LOG_LEVEL_FORCE:
1185 outc = sprintf(outbuf, "Privoxy(%08lx) Force: ", this_thread);
1187 #endif /* def FEATURE_FORCE_LOAD */
1188 #ifdef FEATURE_FAST_REDIRECTS
1189 case LOG_LEVEL_REDIRECTS:
1190 outc = sprintf(outbuf, "Privoxy(%08lx) Redirect: ", this_thread);
1192 #endif /* def FEATURE_FAST_REDIRECTS */
1193 case LOG_LEVEL_DEANIMATE:
1194 outc = sprintf(outbuf, "Privoxy(%08lx) Gif-Deanimate: ", this_thread);
1197 outbuf = outbuf_save;
1201 #ifdef FEATURE_KILL_POPUPS
1202 case LOG_LEVEL_POPUPS:
1203 outc = sprintf(outbuf, "Privoxy(%08lx) Kill-Popups: ", this_thread);
1205 #endif /* def FEATURE_KILL_POPUPS */
1207 outc = sprintf(outbuf, "Privoxy(%08lx) CGI: ", this_thread);
1210 outc = sprintf(outbuf, "Privoxy(%08lx) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
1214 /* get ready to scan var. args. */
1215 va_start( ap, fmt );
1217 /* build formatted message from fmt and var-args */
1218 while ((*src) && (outc < BUFFER_SIZE-2))
1220 char tempbuf[BUFFER_SIZE];
1225 unsigned long ulval;
1232 outbuf[outc++] = ch;
1239 outbuf[outc++] = '%';
1242 ival = va_arg( ap, int );
1244 outc += sprintf(tempbuf, "%d", ival);
1245 if (outc < BUFFER_SIZE-1)
1247 strcpy(outbuf + oldoutc, tempbuf);
1251 outbuf[oldoutc] = '\0';
1255 uval = va_arg( ap, unsigned );
1257 outc += sprintf(tempbuf, "%u", uval);
1258 if (outc < BUFFER_SIZE-1)
1260 strcpy(outbuf + oldoutc, tempbuf);
1264 outbuf[oldoutc] = '\0';
1268 /* this is a modifier that must be followed by u or d */
1272 lval = va_arg( ap, long );
1274 outc += sprintf(tempbuf, "%ld", lval);
1278 ulval = va_arg( ap, unsigned long );
1280 outc += sprintf(tempbuf, "%lu", ulval);
1285 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1287 "Exiting.", this_thread, fmt);
1292 fputs(outbuf, logfp);
1293 fatal_error(outbuf);
1294 /* Never get here */
1297 if (outc < BUFFER_SIZE-1)
1299 strcpy(outbuf + oldoutc, tempbuf);
1303 outbuf[oldoutc] = '\0';
1308 * Note that char paramaters are converted to int, so we need to
1309 * pass "int" to va_arg. (See K&R, 2nd ed, section A7.3.2, page 202)
1311 outbuf[outc++] = (char) va_arg( ap, int );
1314 sval = va_arg( ap, char * );
1320 outc += strlen(sval);
1321 if (outc < BUFFER_SIZE-1)
1323 strcpy(outbuf + oldoutc, sval);
1327 outbuf[oldoutc] = '\0';
1331 /* Non-standard: Print a counted string. Takes 2 parameters:
1332 * int length, const char * string
1334 ival = va_arg( ap, int );
1335 sval = va_arg( ap, char * );
1346 if (outc < BUFFER_SIZE-1)
1348 memcpy(outbuf + oldoutc, sval, (size_t) ival);
1352 outbuf[oldoutc] = '\0';
1356 /* Non-standard: Print error code from errno */
1358 ival = WSAGetLastError();
1359 sval = w32_socket_strerr(ival, tempbuf);
1361 ival = sock_errno();
1363 sval = os2_socket_strerr(ival, tempbuf);
1367 sval = strerror(ival);
1369 #else /* ifndef _WIN32 */
1371 #ifdef HAVE_STRERROR
1372 sval = strerror(ival);
1373 #else /* ifndef HAVE_STRERROR */
1375 #endif /* ndef HAVE_STRERROR */
1378 sprintf(tempbuf, "(errno = %d)", ival);
1381 #endif /* ndef _WIN32 */
1383 outc += strlen(sval);
1384 if (outc < BUFFER_SIZE-1)
1386 strcpy(outbuf + oldoutc, sval);
1390 outbuf[oldoutc] = '\0';
1394 /* Non-standard: Print a Common Log File timestamp */
1397 * Write timestamp into tempbuf.
1399 * Complex because not all OSs have tm_gmtoff or
1400 * the %z field in strftime()
1405 #ifdef HAVE_LOCALTIME_R
1408 int days, hrs, mins;
1410 #ifdef HAVE_GMTIME_R
1411 gmt = *gmtime_r(&now, &gmt);
1412 #elif FEATURE_PTHREAD
1413 pthread_mutex_lock(&gmtime_mutex);
1414 gmt = *gmtime(&now);
1415 pthread_mutex_unlock(&gmtime_mutex);
1417 gmt = *gmtime(&now);
1419 #ifdef HAVE_LOCALTIME_R
1420 tm_now = localtime_r(&now, &dummy);
1421 #elif FEATURE_PTHREAD
1422 pthread_mutex_lock(&localtime_mutex);
1423 tm_now = localtime (&now);
1424 pthread_mutex_unlock(&localtime_mutex);
1426 tm_now = localtime (&now);
1428 days = tm_now->tm_yday - gmt.tm_yday;
1429 hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour);
1430 mins = hrs * 60 + tm_now->tm_min - gmt.tm_min;
1431 strftime (tempbuf, BUFFER_SIZE-6, "%d/%b/%Y:%H:%M:%S ", tm_now);
1432 sprintf (tempbuf + strlen(tempbuf), "%+03d%02d", mins / 60, abs(mins) % 60);
1435 outc += strlen(tempbuf);
1436 if (outc < BUFFER_SIZE-1)
1438 strcpy(outbuf + oldoutc, tempbuf);
1442 outbuf[oldoutc] = '\0';
1446 sprintf(outbuf, "Privoxy(%08lx) Error: log_error(): Bad format string:\n"
1448 "Exiting.", this_thread, fmt);
1453 fputs(outbuf_save, logfp);
1455 fatal_error(outbuf_save);
1456 /* Never get here */
1461 } /* for( p ... ) */
1463 /* done with var. args */
1466 if (outc >= BUFFER_SIZE-2)
1468 /* insufficient room for newline and trailing null. */
1470 static const char warning[] = "... [too long, truncated]\n";
1472 if (outc < BUFFER_SIZE)
1474 /* Need to add terminating null in this case. */
1475 outbuf[outc] = '\0';
1478 /* Truncate output */
1479 outbuf[BUFFER_SIZE - sizeof(warning)] = '\0';
1481 /* Append warning */
1482 strcat(outbuf, warning);
1486 /* Add terminating newline and null */
1487 outbuf[outc++] = '\n';
1488 outbuf[outc] = '\0';
1491 /* deal with glibc stupidity - it won't let you initialize logfp */
1497 fputs(outbuf_save, logfp);
1499 if (loglevel == LOG_LEVEL_FATAL)
1501 fatal_error(outbuf_save);
1502 /* Never get here */
1507 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
1508 /* Write to display */
1509 LogPutString(outbuf_save);
1510 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
1513 #endif /* defined(USE_NEW_LOG_ERROR) */
1516 /*********************************************************************
1518 * Function : jb_err_to_string
1520 * Description : Translates JB_ERR_FOO codes into strings.
1522 * XXX: the type of error codes is jb_err
1523 * but the typedef'inition is currently not
1524 * visible to all files that include errlog.h.
1527 * 1 : error = a valid jb_err code
1529 * Returns : A string with the jb_err translation
1531 *********************************************************************/
1532 const char *jb_err_to_string(int error)
1537 return "Success, no error";
1539 return "Out of memory";
1540 case JB_ERR_CGI_PARAMS:
1541 return "Missing or corrupt CGI parameters";
1543 return "Error opening, reading or writing a file";
1545 return "Parse error";
1546 case JB_ERR_MODIFIED:
1547 return "File has been modified outside of the CGI actions editor.";
1548 case JB_ERR_COMPRESS:
1549 return "(De)compression failure";
1552 return "Unknown error";
1555 return "Internal error";
1559 /*********************************************************************
1561 * Function : w32_socket_strerr
1563 * Description : Translate the return value from WSAGetLastError()
1567 * 1 : errcode = The return value from WSAGetLastError().
1568 * 2 : tmp_buf = A temporary buffer that might be used to
1571 * Returns : String representing the error code. This may be
1572 * a global string constant or a string stored in
1575 *********************************************************************/
1576 static char *w32_socket_strerr(int errcode, char *tmp_buf)
1578 #define TEXT_FOR_ERROR(code,text) \
1579 if (errcode == code) \
1581 return #code " - " text; \
1584 TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
1585 TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
1586 TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
1587 TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
1588 TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
1589 TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
1590 TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
1591 TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
1592 TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
1593 TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
1594 TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
1595 TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
1596 TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
1597 TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
1598 TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
1599 TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
1600 TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
1601 TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
1602 TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
1603 TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
1604 TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
1605 TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
1606 TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
1607 TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
1608 TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
1609 TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
1610 TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
1611 TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
1612 TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
1613 TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
1614 TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
1615 TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
1616 TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
1617 TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
1618 TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
1619 TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
1620 TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
1621 TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
1622 TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
1623 TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
1624 TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
1625 TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
1627 * The following error codes are documented in the Microsoft WinSock
1628 * reference guide, but don't actually exist.
1630 * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
1631 * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
1632 * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
1633 * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
1634 * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
1635 * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
1636 * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
1637 * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
1638 * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
1639 * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
1642 sprintf(tmp_buf, "(error number %d)", errcode);
1645 #endif /* def _WIN32 */
1649 /*********************************************************************
1651 * Function : os2_socket_strerr
1653 * Description : Translate the return value from sock_errno()
1657 * 1 : errcode = The return value from sock_errno().
1658 * 2 : tmp_buf = A temporary buffer that might be used to
1661 * Returns : String representing the error code. This may be
1662 * a global string constant or a string stored in
1665 *********************************************************************/
1666 static char *os2_socket_strerr(int errcode, char *tmp_buf)
1668 #define TEXT_FOR_ERROR(code,text) \
1669 if (errcode == code) \
1671 return #code " - " text; \
1674 TEXT_FOR_ERROR(SOCEPERM , "Not owner.")
1675 TEXT_FOR_ERROR(SOCESRCH , "No such process.")
1676 TEXT_FOR_ERROR(SOCEINTR , "Interrupted system call.")
1677 TEXT_FOR_ERROR(SOCENXIO , "No such device or address.")
1678 TEXT_FOR_ERROR(SOCEBADF , "Bad file number.")
1679 TEXT_FOR_ERROR(SOCEACCES , "Permission denied.")
1680 TEXT_FOR_ERROR(SOCEFAULT , "Bad address.")
1681 TEXT_FOR_ERROR(SOCEINVAL , "Invalid argument.")
1682 TEXT_FOR_ERROR(SOCEMFILE , "Too many open files.")
1683 TEXT_FOR_ERROR(SOCEPIPE , "Broken pipe.")
1684 TEXT_FOR_ERROR(SOCEWOULDBLOCK , "Operation would block.")
1685 TEXT_FOR_ERROR(SOCEINPROGRESS , "Operation now in progress.")
1686 TEXT_FOR_ERROR(SOCEALREADY , "Operation already in progress.")
1687 TEXT_FOR_ERROR(SOCENOTSOCK , "Socket operation on non-socket.")
1688 TEXT_FOR_ERROR(SOCEDESTADDRREQ , "Destination address required.")
1689 TEXT_FOR_ERROR(SOCEMSGSIZE , "Message too long.")
1690 TEXT_FOR_ERROR(SOCEPROTOTYPE , "Protocol wrong type for socket.")
1691 TEXT_FOR_ERROR(SOCENOPROTOOPT , "Protocol not available.")
1692 TEXT_FOR_ERROR(SOCEPROTONOSUPPORT, "Protocol not supported.")
1693 TEXT_FOR_ERROR(SOCESOCKTNOSUPPORT, "Socket type not supported.")
1694 TEXT_FOR_ERROR(SOCEOPNOTSUPP , "Operation not supported.")
1695 TEXT_FOR_ERROR(SOCEPFNOSUPPORT , "Protocol family not supported.")
1696 TEXT_FOR_ERROR(SOCEAFNOSUPPORT , "Address family not supported by protocol family.")
1697 TEXT_FOR_ERROR(SOCEADDRINUSE , "Address already in use.")
1698 TEXT_FOR_ERROR(SOCEADDRNOTAVAIL , "Can't assign requested address.")
1699 TEXT_FOR_ERROR(SOCENETDOWN , "Network is down.")
1700 TEXT_FOR_ERROR(SOCENETUNREACH , "Network is unreachable.")
1701 TEXT_FOR_ERROR(SOCENETRESET , "Network dropped connection on reset.")
1702 TEXT_FOR_ERROR(SOCECONNABORTED , "Software caused connection abort.")
1703 TEXT_FOR_ERROR(SOCECONNRESET , "Connection reset by peer.")
1704 TEXT_FOR_ERROR(SOCENOBUFS , "No buffer space available.")
1705 TEXT_FOR_ERROR(SOCEISCONN , "Socket is already connected.")
1706 TEXT_FOR_ERROR(SOCENOTCONN , "Socket is not connected.")
1707 TEXT_FOR_ERROR(SOCESHUTDOWN , "Can't send after socket shutdown.")
1708 TEXT_FOR_ERROR(SOCETOOMANYREFS , "Too many references: can't splice.")
1709 TEXT_FOR_ERROR(SOCETIMEDOUT , "Operation timed out.")
1710 TEXT_FOR_ERROR(SOCECONNREFUSED , "Connection refused.")
1711 TEXT_FOR_ERROR(SOCELOOP , "Too many levels of symbolic links.")
1712 TEXT_FOR_ERROR(SOCENAMETOOLONG , "File name too long.")
1713 TEXT_FOR_ERROR(SOCEHOSTDOWN , "Host is down.")
1714 TEXT_FOR_ERROR(SOCEHOSTUNREACH , "No route to host.")
1715 TEXT_FOR_ERROR(SOCENOTEMPTY , "Directory not empty.")
1716 TEXT_FOR_ERROR(SOCEOS2ERR , "OS/2 Error.")
1718 sprintf(tmp_buf, "(error number %d)", errcode);
1721 #endif /* def __OS2__ */