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