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