Changes for AmigaOS added.
[privoxy.git] / errlog.c
1 const char errlog_rcs[] = "$Id: errlog.c,v 1.9 2001/05/28 16:15:17 jongfoster Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/errlog.c,v $
5  *
6  * Purpose     :  Log errors to a designated destination in an elegant,
7  *                printf-like fashion.
8  *
9  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
10  *                IJBSWA team.  http://ijbswa.sourceforge.net
11  *
12  *                Based on the Internet Junkbuster originally written
13  *                by and Copyright (C) 1997 Anonymous Coders and 
14  *                Junkbusters Corporation.  http://www.junkbusters.com
15  *
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.
21  *
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.
27  *
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.
33  *
34  * Revisions   :
35  *    $Log: errlog.c,v $
36  *    Revision 1.9  2001/05/28 16:15:17  jongfoster
37  *    Improved reporting of errors under Win32.
38  *
39  *    Revision 1.8  2001/05/26 17:25:14  jongfoster
40  *    Added support for CLF (Common Log Format) and fixed LOG_LEVEL_LOG
41  *
42  *    Revision 1.7  2001/05/26 15:21:28  jongfoster
43  *    Activity animation in Win32 GUI now works even if debug==0
44  *
45  *    Revision 1.6  2001/05/25 21:55:08  jongfoster
46  *    Now cleans up properly on FATAL (removes taskbar icon etc)
47  *
48  *    Revision 1.5  2001/05/22 18:46:04  oes
49  *
50  *    - Enabled filtering banners by size rather than URL
51  *      by adding patterns that replace all standard banner
52  *      sizes with the "Junkbuster" gif to the re_filterfile
53  *
54  *    - Enabled filtering WebBugs by providing a pattern
55  *      which kills all 1x1 images
56  *
57  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
58  *      which is selected by the (nonstandard and therefore
59  *      capital) letter 'U' in the option string.
60  *      It causes the quantifiers to be ungreedy by default.
61  *      Appending a ? turns back to greedy (!).
62  *
63  *    - Added a new interceptor ijb-send-banner, which
64  *      sends back the "Junkbuster" gif. Without imagelist or
65  *      MSIE detection support, or if tinygif = 1, or the
66  *      URL isn't recognized as an imageurl, a lame HTML
67  *      explanation is sent instead.
68  *
69  *    - Added new feature, which permits blocking remote
70  *      script redirects and firing back a local redirect
71  *      to the browser.
72  *      The feature is conditionally compiled, i.e. it
73  *      can be disabled with --disable-fast-redirects,
74  *      plus it must be activated by a "fast-redirects"
75  *      line in the config file, has its own log level
76  *      and of course wants to be displayed by show-proxy-args
77  *      Note: Boy, all the #ifdefs in 1001 locations and
78  *      all the fumbling with configure.in and acconfig.h
79  *      were *way* more work than the feature itself :-(
80  *
81  *    - Because a generic redirect template was needed for
82  *      this, tinygif = 3 now uses the same.
83  *
84  *    - Moved GIFs, and other static HTTP response templates
85  *      to project.h
86  *
87  *    - Some minor fixes
88  *
89  *    - Removed some >400 CRs again (Jon, you really worked
90  *      a lot! ;-)
91  *
92  *    Revision 1.4  2001/05/21 19:32:54  jongfoster
93  *    Added another #ifdef _WIN_CONSOLE
94  *
95  *    Revision 1.3  2001/05/20 01:11:40  jongfoster
96  *    Added support for LOG_LEVEL_FATAL
97  *    Renamed LOG_LEVEL_FRC to LOG_LEVEL_FORCE,
98  *    and LOG_LEVEL_REF to LOG_LEVEL_RE_FILTER
99  *
100  *    Revision 1.2  2001/05/17 22:42:01  oes
101  *     - Cleaned CRLF's from the sources and related files
102  *     - Repaired logging for REF and FRC
103  *
104  *    Revision 1.1.1.1  2001/05/15 13:58:51  oes
105  *    Initial import of version 2.9.3 source tree
106  *
107  *
108  *********************************************************************/
109 \f
110
111 #include "config.h"
112
113 #include <stdlib.h>
114 #include <stdio.h>
115 #include <stdarg.h>
116 #include <string.h>
117
118 #ifndef _WIN32
119 #include <unistd.h>
120 #endif /* ndef _WIN32 */
121
122 #include <errno.h>
123 /* #include <pthread.h> */
124
125 #ifdef _WIN32
126 #include <windows.h>
127 #ifndef _WIN_CONSOLE
128 #include "w32log.h"
129 #endif /* ndef _WIN_CONSOLE */
130 #endif /* def _WIN32 */
131
132 #include "errlog.h"
133 #include "project.h"
134
135 const char errlog_h_rcs[] = ERRLOG_H_VERSION;
136
137
138 /*
139  * LOG_LEVEL_FATAL cannot be turned off.  (There are
140  * some exceptional situations where we need to get a
141  * message to the user).
142  */
143 #define LOG_LEVEL_MINIMUM  LOG_LEVEL_FATAL
144
145 /* where to log (default: stderr) */
146 static FILE *logfp = NULL;
147
148 /* where to log (NULL == stderr) */
149 static char * logfilename = NULL;
150
151 /* logging detail level.  */
152 static int debug = (LOG_LEVEL_FATAL | LOG_LEVEL_ERROR | LOG_LEVEL_INFO);  
153
154 /* static functions */
155 static void fatal_error(const char * error_message);
156 static char * w32_socket_strerr(int errcode, char * tmp_buf);
157
158
159 /*********************************************************************
160  *
161  * Function    :  fatal_error
162  *
163  * Description :  Displays a fatal error to standard error (or, on 
164  *                a WIN32 GUI, to a dialog box), and exits
165  *                JunkBuster with status code 1.
166  *
167  * Parameters  :
168  *          1  :  error_message = The error message to display.
169  *
170  * Returns     :  Does not return.
171  *
172  *********************************************************************/
173 static void fatal_error(const char * error_message)
174 {
175 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
176    MessageBox(g_hwndLogFrame, error_message, "Internet JunkBuster Error", 
177       MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);  
178
179    /* Cleanup - remove taskbar icon etc. */
180    TermLogWindow();
181
182 #else /* if !defined(_WIN32) || defined(_WIN_CONSOLE) */
183    fputs(error_message, stderr);
184 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
185
186    exit(1);
187 }
188
189
190 /*********************************************************************
191  *
192  * Function    :  init_errlog
193  *
194  * Description :  Initializes the logging module.  Must call before
195  *                calling log_error.
196  *
197  * Parameters  :
198  *          1  :  prog_name  = The program name.
199  *          2  :  logfname   = The logfile name, or NULL for stderr.
200  *          3  :  debuglevel = The debugging level.
201  *
202  * Returns     :  N/A
203  *
204  *********************************************************************/
205 void init_error_log(const char *prog_name, const char *logfname, int debuglevel)
206 {
207    FILE *fp;
208
209    /* FIXME RACE HAZARD: should start critical section error_log_use here */
210
211    /* set the logging detail level */
212    debug = debuglevel | LOG_LEVEL_MINIMUM;
213
214    if ((logfp != NULL) && (logfp != stderr))
215    {
216       fclose(logfp);
217    }
218    logfp = stderr;
219
220    /* set the designated log file */
221    if( logfname )
222    {
223       if( !(fp = fopen(logfname, "a")) )
224       {
225          log_error(LOG_LEVEL_FATAL, "init_errlog(): can't open logfile: %s", logfname);
226       }
227
228       /* set logging to be completely unbuffered */
229       setbuf(fp, NULL);
230
231       logfp = fp;
232    }
233
234    log_error(LOG_LEVEL_INFO, "Internet JunkBuster version " VERSION);
235    if (prog_name != NULL)
236    {
237       log_error(LOG_LEVEL_INFO, "Program name: %s", prog_name);
238    }
239
240    /* FIXME RACE HAZARD: should end critical section error_log_use here */
241
242 } /* init_error_log */
243
244
245 /*********************************************************************
246  *
247  * Function    :  log_error
248  *
249  * Description :  This is the error-reporting and logging function.
250  *
251  * Parameters  :
252  *          1  :  loglevel  = the type of message to be logged
253  *          2  :  fmt       = the main string we want logged, printf-like
254  *          3  :  ...       = arguments to be inserted in fmt (printf-like).
255  *
256  * Returns     :  N/A
257  *
258  *********************************************************************/
259 void log_error(int loglevel, char *fmt, ...)
260 {
261    va_list ap;
262    char outbuf[BUFSIZ];
263    char * src = fmt;
264    int outc = 0;
265    long this_thread = 1;  /* was: pthread_t this_thread;*/
266
267 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
268    /*
269     * Irrespective of debug setting, a GET/POST/CONNECT makes
270     * the taskbar icon animate.  (There is an option to disable
271     * this but checking that is handled inside LogShowActivity()).
272     */
273    if (loglevel == LOG_LEVEL_GPC)
274    {
275       LogShowActivity();
276    }
277 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
278
279    /* verify if loglevel applies to current settings and bail out if negative */
280    if ((loglevel & debug) == 0)
281    {
282       return;
283    }
284
285    /* FIXME get current thread id */
286    /* this_thread = (long)pthread_self(); */
287
288    switch (loglevel)
289    {
290       case LOG_LEVEL_ERROR:
291          outc = sprintf(outbuf, "IJB(%d) Error: ", this_thread);
292          break;
293       case LOG_LEVEL_FATAL:
294          outc = sprintf(outbuf, "IJB(%d) Fatal error: ", this_thread);
295          break;
296       case LOG_LEVEL_GPC:
297          outc = sprintf(outbuf, "IJB(%d) Request: ", this_thread);
298          break;
299       case LOG_LEVEL_CONNECT:
300          outc = sprintf(outbuf, "IJB(%d) Connect: ", this_thread);
301          break;
302       case LOG_LEVEL_LOG:
303          outc = sprintf(outbuf, "IJB(%d) Writing: ", this_thread);
304          break;
305       case LOG_LEVEL_HEADER:
306          outc = sprintf(outbuf, "IJB(%d) Header: ", this_thread);
307          break;
308       case LOG_LEVEL_INFO:
309          outc = sprintf(outbuf, "IJB(%d) Info: ", this_thread);
310          break;
311 #ifdef PCRS
312       case LOG_LEVEL_RE_FILTER:
313          outc = sprintf(outbuf, "IJB(%d) Re-Filter: ", this_thread);
314          break;
315 #endif /* def PCRS */
316 #ifdef FORCE_LOAD
317       case LOG_LEVEL_FORCE:
318          outc = sprintf(outbuf, "IJB(%d) Force: ", this_thread);
319          break;
320 #endif /* def FORCE_LOAD */
321 #ifdef FAST_REDIRECTS
322       case LOG_LEVEL_REDIRECTS:
323          outc = sprintf(outbuf, "IJB(%d) Redirect: ", this_thread);
324          break;
325 #endif /* def FAST_REDIRECTS */
326       case LOG_LEVEL_CLF:
327          outc = 0;
328          outbuf[0] = '\0';
329          break;
330       default:
331          outc = sprintf(outbuf, "IJB(%d) UNKNOWN LOG TYPE(%d): ", this_thread, loglevel);
332          break;
333    }
334    
335    /* get ready to scan var. args. */
336    va_start( ap, fmt );
337
338    /* build formatted message from fmt and var-args */
339    while ((*src) && (outc < BUFSIZ-2))
340    {
341       char tempbuf[BUFSIZ];
342       char *sval;
343       int ival;
344       unsigned uval;
345       long lval;
346       unsigned long ulval;
347       int oldoutc;
348       char ch;
349       
350       ch = *src++;
351       if( ch != '%' )
352       {
353          outbuf[outc++] = ch;
354          continue;
355       }
356
357       ch = *src++;
358       switch (ch) {
359          case '%':
360             outbuf[outc++] = '%';
361             break;
362          case 'd':
363             ival = va_arg( ap, int );
364             oldoutc = outc;
365             outc += sprintf(tempbuf, "%d", ival);
366             if (outc < BUFSIZ-1) 
367             {
368                strcpy(outbuf + oldoutc, tempbuf);
369             }
370             else
371             {
372                outbuf[oldoutc] = '\0';
373             }
374             break;
375          case 'u':
376             uval = va_arg( ap, unsigned );
377             oldoutc = outc;
378             outc += sprintf(tempbuf, "%u", uval);
379             if (outc < BUFSIZ-1) 
380             {
381                strcpy(outbuf + oldoutc, tempbuf);
382             }
383             else
384             {
385                outbuf[oldoutc] = '\0';
386             }
387             break;
388          case 'l':
389             /* this is a modifier that must be followed by u or d */
390             ch = *src++;
391             if (ch == 'd')
392             {
393                lval = va_arg( ap, long );
394                oldoutc = outc;
395                outc += sprintf(tempbuf, "%ld", lval);
396             }
397             else if (ch == 'u')
398             {
399                ulval = va_arg( ap, unsigned long );
400                oldoutc = outc;
401                outc += sprintf(tempbuf, "%lu", ulval);
402             }
403             else
404             {
405                /* Error */
406                sprintf(outbuf, "IJB(%d) Error: log_error(): Bad format string:\n"
407                                "Format = \"%s\"\n"
408                                "Exiting.", this_thread, fmt);
409                /* FIXME RACE HAZARD: should start critical section error_log_use here */
410                if( !logfp )
411                {
412                   logfp = stderr;
413                }
414                fputs(outbuf, logfp);
415                /* FIXME RACE HAZARD: should end critical section error_log_use here */
416                fatal_error(outbuf);
417                /* Never get here */
418                break;
419             }
420             if (outc < BUFSIZ-1) 
421             {
422                strcpy(outbuf + oldoutc, tempbuf);
423             }
424             else
425             {
426                outbuf[oldoutc] = '\0';
427             }
428             break;
429          case 'c':
430             /*
431              * Note that char paramaters are converted to int, so we need to
432              * pass "int" to va_arg.  (See K&R, 2nd ed, section A7.3.2, page 202)
433              */
434             outbuf[outc++] = (char) va_arg( ap, int );
435             break;
436          case 's':
437             sval = va_arg( ap, char * );
438             oldoutc = outc;
439             outc += strlen(sval);
440             if (outc < BUFSIZ-1) 
441             {
442                strcpy(outbuf + oldoutc, sval);
443             }
444             else
445             {
446                outbuf[oldoutc] = '\0';
447             }
448             break;
449          case 'N':
450             /* Non-standard: Print a counted string.  Takes 2 parameters:
451              * int length, const char * string
452              */
453             ival = va_arg( ap, int );
454             sval = va_arg( ap, char * );
455             if (ival < 0)
456             {
457                ival = 0;
458             }
459             oldoutc = outc;
460             outc += ival;
461             if (outc < BUFSIZ-1)
462             {
463                memcpy(outbuf + oldoutc, sval, ival);
464             }
465             else
466             {
467                outbuf[oldoutc] = '\0';
468             }
469             break;
470          case 'E':
471             /* Non-standard: Print error code from errno */
472 #ifdef _WIN32
473             ival = WSAGetLastError();
474             sval = w32_socket_strerr(ival, tempbuf);
475 #else /* ifndef _WIN32 */
476             ival = errno; 
477 #ifndef NOSTRERROR
478             sval = strerror(ival);
479 #else /* def NOSTRERROR */
480             sval = NULL;
481 #endif /* def NOSTRERROR */
482             if (sval == NULL)
483             {
484                sprintf(tempbuf, "(errno = %d)", ival);
485                sval = tempbuf;
486             }
487 #endif /* ndef _WIN32 */
488             oldoutc = outc;
489             outc += strlen(sval);
490             if (outc < BUFSIZ-1) 
491             {
492                strcpy(outbuf + oldoutc, sval);
493             }
494             else
495             {
496                outbuf[oldoutc] = '\0';
497             }
498             break;
499          case 'T':
500             /* Non-standard: Print a Common Log File timestamp */
501             {
502                /*
503                 * Write timestamp into tempbuf.
504                 *
505                 * Complex because not all OSs have tm_gmtoff or
506                 * the %z field in strftime()
507                 */
508                time_t now; 
509                struct tm *tm_now; 
510                struct tm gmt; 
511                int days, hrs, mins; 
512                time (&now); 
513                gmt = *gmtime (&now); 
514                tm_now = localtime (&now); 
515                days = tm_now->tm_yday - gmt.tm_yday; 
516                hrs = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + tm_now->tm_hour - gmt.tm_hour); 
517                mins = hrs * 60 + tm_now->tm_min - gmt.tm_min; 
518                strftime (tempbuf, BUFSIZ-6, "%d/%b/%Y:%H:%M:%S ", tm_now); 
519                sprintf (tempbuf + strlen(tempbuf), "%+03d%02d", mins / 60, abs(mins) % 60); 
520             }
521             oldoutc = outc;
522             outc += strlen(tempbuf);
523             if (outc < BUFSIZ-1) 
524             {
525                strcpy(outbuf + oldoutc, tempbuf);
526             }
527             else
528             {
529                outbuf[oldoutc] = '\0';
530             }
531             break;
532          default:
533             sprintf(outbuf, "IJB(%d) Error: log_error(): Bad format string:\n"
534                             "Format = \"%s\"\n"
535                             "Exiting.", this_thread, fmt);
536             /* FIXME RACE HAZARD: should start critical section error_log_use here */
537             if( !logfp )
538             {
539                logfp = stderr;
540             }
541             fputs(outbuf, logfp);
542             /* FIXME RACE HAZARD: should end critical section error_log_use here */
543             fatal_error(outbuf);
544             /* Never get here */
545             break;
546
547       } /* switch( p ) */
548
549    } /* for( p ... ) */
550    
551    /* done with var. args */
552    va_end( ap );
553    
554    if (outc >= BUFSIZ-2)
555    {
556       /* insufficient room for newline and trailing null. */
557
558       static const char warning[] = "... [too long, truncated]\n";
559
560       if (outc < BUFSIZ)
561       {
562          /* Need to add terminating null in this case. */
563          outbuf[outc] = '\0';
564       }
565
566       /* Truncate output */
567       outbuf[BUFSIZ - sizeof(warning)] = '\0';
568
569       /* Append warning */
570       strcat(outbuf, warning);
571    }
572    else
573    {
574       /* Add terminating newline and null */
575       outbuf[outc++] = '\n';
576       outbuf[outc] = '\0';
577    }
578
579    /* FIXME RACE HAZARD: should start critical section error_log_use here */
580
581    /* deal with glibc stupidity - it won't let you initialize logfp */
582    if( !logfp )
583    {
584       logfp = stderr;
585    }
586
587    fputs(outbuf, logfp);
588
589    if (loglevel == LOG_LEVEL_FATAL)
590    {
591       fatal_error(outbuf);
592       /* Never get here */
593    }
594
595    /* FIXME RACE HAZARD: should end critical section error_log_use here */
596
597 #if defined(_WIN32) && !defined(_WIN_CONSOLE)
598    /* Write to display */
599    LogPutString(outbuf);
600 #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
601
602 }
603
604
605 #ifdef _WIN32
606 /*********************************************************************
607  *
608  * Function    :  w32_socket_strerr
609  *
610  * Description :  Translate the return value from WSAGetLastError()
611  *                into a string.
612  *
613  * Parameters  :
614  *          1  :  errcode = The return value from WSAGetLastError().
615  *          2  :  tmp_buf = A temporary buffer that might be used to
616  *                          store the string.
617  *
618  * Returns     :  String representing the error code.  This may be
619  *                a global string constant or a string stored in
620  *                tmp_buf.
621  *
622  *********************************************************************/
623 static char * w32_socket_strerr(int errcode, char * tmp_buf)
624 {
625 #define TEXT_FOR_ERROR(code,text) \
626    if (errcode == code)           \
627    {                              \
628       return #code " - " text;    \
629    }
630
631    TEXT_FOR_ERROR(WSAEACCES, "Permission denied")
632    TEXT_FOR_ERROR(WSAEADDRINUSE, "Address already in use.")
633    TEXT_FOR_ERROR(WSAEADDRNOTAVAIL, "Cannot assign requested address.");
634    TEXT_FOR_ERROR(WSAEAFNOSUPPORT, "Address family not supported by protocol family.");
635    TEXT_FOR_ERROR(WSAEALREADY, "Operation already in progress.");
636    TEXT_FOR_ERROR(WSAECONNABORTED, "Software caused connection abort.");
637    TEXT_FOR_ERROR(WSAECONNREFUSED, "Connection refused.");
638    TEXT_FOR_ERROR(WSAECONNRESET, "Connection reset by peer.");
639    TEXT_FOR_ERROR(WSAEDESTADDRREQ, "Destination address required.");
640    TEXT_FOR_ERROR(WSAEFAULT, "Bad address.");
641    TEXT_FOR_ERROR(WSAEHOSTDOWN, "Host is down.");
642    TEXT_FOR_ERROR(WSAEHOSTUNREACH, "No route to host.");
643    TEXT_FOR_ERROR(WSAEINPROGRESS, "Operation now in progress.");
644    TEXT_FOR_ERROR(WSAEINTR, "Interrupted function call.");
645    TEXT_FOR_ERROR(WSAEINVAL, "Invalid argument.");
646    TEXT_FOR_ERROR(WSAEISCONN, "Socket is already connected.");
647    TEXT_FOR_ERROR(WSAEMFILE, "Too many open sockets.");
648    TEXT_FOR_ERROR(WSAEMSGSIZE, "Message too long.");
649    TEXT_FOR_ERROR(WSAENETDOWN, "Network is down.");
650    TEXT_FOR_ERROR(WSAENETRESET, "Network dropped connection on reset.");
651    TEXT_FOR_ERROR(WSAENETUNREACH, "Network is unreachable.");
652    TEXT_FOR_ERROR(WSAENOBUFS, "No buffer space available.");
653    TEXT_FOR_ERROR(WSAENOPROTOOPT, "Bad protocol option.");
654    TEXT_FOR_ERROR(WSAENOTCONN, "Socket is not connected.");
655    TEXT_FOR_ERROR(WSAENOTSOCK, "Socket operation on non-socket.");
656    TEXT_FOR_ERROR(WSAEOPNOTSUPP, "Operation not supported.");
657    TEXT_FOR_ERROR(WSAEPFNOSUPPORT, "Protocol family not supported.");
658    TEXT_FOR_ERROR(WSAEPROCLIM, "Too many processes.");
659    TEXT_FOR_ERROR(WSAEPROTONOSUPPORT, "Protocol not supported.");
660    TEXT_FOR_ERROR(WSAEPROTOTYPE, "Protocol wrong type for socket.");
661    TEXT_FOR_ERROR(WSAESHUTDOWN, "Cannot send after socket shutdown.");
662    TEXT_FOR_ERROR(WSAESOCKTNOSUPPORT, "Socket type not supported.");
663    TEXT_FOR_ERROR(WSAETIMEDOUT, "Connection timed out.");
664    TEXT_FOR_ERROR(WSAEWOULDBLOCK, "Resource temporarily unavailable.");
665    TEXT_FOR_ERROR(WSAHOST_NOT_FOUND, "Host not found.");
666    TEXT_FOR_ERROR(WSANOTINITIALISED, "Successful WSAStartup not yet performed.");
667    TEXT_FOR_ERROR(WSANO_DATA, "Valid name, no data record of requested type.");
668    TEXT_FOR_ERROR(WSANO_RECOVERY, "This is a non-recoverable error.");
669    TEXT_FOR_ERROR(WSASYSNOTREADY, "Network subsystem is unavailable.");
670    TEXT_FOR_ERROR(WSATRY_AGAIN, "Non-authoritative host not found.");
671    TEXT_FOR_ERROR(WSAVERNOTSUPPORTED, "WINSOCK.DLL version out of range.");
672    TEXT_FOR_ERROR(WSAEDISCON, "Graceful shutdown in progress.");
673    /*
674     * The following error codes are documented in the Microsoft WinSock
675     * reference guide, but don't actually exist.
676     *
677     * TEXT_FOR_ERROR(WSA_INVALID_HANDLE, "Specified event object handle is invalid.");
678     * TEXT_FOR_ERROR(WSA_INVALID_PARAMETER, "One or more parameters are invalid.");
679     * TEXT_FOR_ERROR(WSAINVALIDPROCTABLE, "Invalid procedure table from service provider.");
680     * TEXT_FOR_ERROR(WSAINVALIDPROVIDER, "Invalid service provider version number.");
681     * TEXT_FOR_ERROR(WSA_IO_PENDING, "Overlapped operations will complete later.");
682     * TEXT_FOR_ERROR(WSA_IO_INCOMPLETE, "Overlapped I/O event object not in signaled state.");
683     * TEXT_FOR_ERROR(WSA_NOT_ENOUGH_MEMORY, "Insufficient memory available.");
684     * TEXT_FOR_ERROR(WSAPROVIDERFAILEDINIT, "Unable to initialize a service provider.");
685     * TEXT_FOR_ERROR(WSASYSCALLFAILURE, "System call failure.");
686     * TEXT_FOR_ERROR(WSA_OPERATION_ABORTED, "Overlapped operation aborted.");
687     */
688
689    sprintf(tmp_buf, "(error number %d)", errcode);
690    return tmp_buf;
691 }
692 #endif /* def _WIN32 */
693
694
695 /*
696   Local Variables:
697   tab-width: 3
698   end:
699 */
700