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