1 /*
2  * $LynxId: HTUtils.h,v 1.115 2013/07/28 23:04:57 tom Exp $
3  *
4  * Utility macros for the W3 code library
5  * MACROS FOR GENERAL USE
6  *
7  * See also:  the system dependent file "www_tcp.h", which is included here.
8  */
9 
10 #ifndef NO_LYNX_TRACE
11 #define DEBUG			/* Turns on trace; turn off for smaller binary */
12 #endif
13 
14 #ifndef HTUTILS_H
15 #define HTUTILS_H
16 
17 #ifdef HAVE_CONFIG_H
18 #include <lynx_cfg.h>		/* generated by autoconf 'configure' script */
19 
20 /* see AC_FUNC_ALLOCA macro */
21 #ifdef __GNUC__
22 # define alloca __builtin_alloca
23 #else
24 # ifdef _MSC_VER
25 #  include <malloc.h>
26 #  define alloca _alloca
27 # else
28 #  if HAVE_ALLOCA_H
29 #   include <alloca.h>
30 #  else
31 #   ifdef _AIX
32 #pragma alloca
33 #   else
34 #    ifndef alloca		/* predefined by HP cc +Olibcalls */
35 char *alloca();
36 
37 #    endif
38 #   endif
39 #  endif
40 # endif
41 #endif
42 
43 #include <sys/types.h>
44 #include <stdio.h>
45 
46 #else /* HAVE_CONFIG_H */
47 
48 #ifdef DJGPP
49 #include <sys/config.h>		/* pseudo-autoconf values for DJGPP libc/headers */
50 #define HAVE_TRUNCATE 1
51 #define HAVE_ALLOCA 1
52 #include <limits.h>
53 #endif /* DJGPP */
54 
55 #include <sys/types.h>
56 #include <stdio.h>
57 
58 /* Explicit system-configure */
59 #ifdef VMS
60 #define NO_SIZECHANGE
61 
62 #if defined(VAXC) && !defined(__DECC)
63 #define NO_UNISTD_H		/* DEC C has unistd.h, but not VAX C */
64 #endif
65 
66 #define NO_KEYPAD
67 #define NO_UTMP
68 
69 #undef NO_FILIO_H
70 #define NO_FILIO_H
71 
72 #define NOUSERS
73 #define DISP_PARTIAL		/* experimental */
74 #endif
75 
76 #if defined(VMS) || defined(_WINDOWS)
77 #define HAVE_STDLIB_H 1
78 #endif
79 
80 /* Accommodate non-autoconf'd Makefiles (VMS, DJGPP, etc) */
81 
82 #ifndef NO_ARPA_INET_H
83 #define HAVE_ARPA_INET_H 1
84 #endif
85 
86 #ifndef NO_CBREAK
87 #define HAVE_CBREAK 1
88 #endif
89 
90 #ifndef NO_CUSERID
91 #define HAVE_CUSERID 1
92 #endif
93 
94 #ifndef NO_FILIO_H
95 #define HAVE_SYS_FILIO_H 1
96 #endif
97 
98 #ifndef NO_GETCWD
99 #define HAVE_GETCWD 1
100 #endif
101 
102 #ifndef USE_SLANG
103 #ifndef NO_KEYPAD
104 #define HAVE_KEYPAD 1
105 #endif
106 #ifndef NO_TTYTYPE
107 #define HAVE_TTYTYPE 1
108 #endif
109 #endif /* USE_SLANG */
110 
111 #ifndef NO_PUTENV
112 #define HAVE_PUTENV 1
113 #endif
114 
115 #ifndef NO_SIZECHANGE
116 #define HAVE_SIZECHANGE 1
117 #endif
118 
119 #ifndef NO_UNISTD_H
120 #undef  HAVE_UNISTD_H
121 #define HAVE_UNISTD_H 1
122 #endif
123 
124 #ifndef NO_UTMP
125 #define HAVE_UTMP 1
126 #endif
127 
128 #endif /* HAVE_CONFIG_H */
129 
130 #include <assert.h>
131 
132 /* suppress inadvertant use of gettext in makeuctb when cross-compiling */
133 #ifdef DONT_USE_GETTEXT
134 #undef HAVE_GETTEXT
135 #undef HAVE_LIBGETTEXT_H
136 #undef HAVE_LIBINTL_H
137 #endif
138 
139 #ifndef lynx_srand
140 #define lynx_srand srand
141 #endif
142 
143 #ifndef lynx_rand
144 #define lynx_rand rand
145 #endif
146 
147 #if '0' != 48
148 #define NOT_ASCII
149 #endif
150 
151 #if '0' == 240
152 #define EBCDIC
153 #endif
154 
155 #ifndef LY_MAXPATH
156 #define LY_MAXPATH 256
157 #endif
158 
159 #ifndef GCC_NORETURN
160 #define GCC_NORETURN		/* nothing */
161 #endif
162 
163 #ifndef GCC_UNUSED
164 #define GCC_UNUSED		/* nothing */
165 #endif
166 
167 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
168 #define USE_IGNORE_RC
169 extern int ignore_unused;
170 
171 #define IGNORE_RC(func) ignore_unused = (int) func
172 #else
173 #define IGNORE_RC(func) (void) func
174 #endif /* gcc workarounds */
175 
176 #if defined(__CYGWIN32__) && ! defined(__CYGWIN__)
177 #define __CYGWIN__ 1
178 #endif
179 
180 #if defined(__CYGWIN__)		/* 1998/12/31 (Thu) 16:13:46 */
181 #ifdef USE_OPENSSL_INCL
182 #define NOCRYPT			/* workaround for openssl 1.0.1e bug */
183 #endif
184 #include <windows.h>		/* #include "windef.h" */
185 #define BOOLEAN_DEFINED
186 #undef HAVE_POPEN		/* FIXME: does this not work, or is it missing */
187 #undef small			/* see <w32api/rpcndr.h> */
188 #endif
189 
190 #ifdef HAVE_ATOLL
191 #define LYatoll(n) atoll(n)
192 #else
193 extern off_t LYatoll(const char *value);
194 #endif
195 
196 /* cygwin, mingw32, etc. */
197 #ifdef FILE_DOES_NOT_EXIST
198 #undef FILE_DOES_NOT_EXIST	/* see <w32api/winnt.h> */
199 #endif
200 
201 /*
202  * VS .NET 2003 includes winsock.h unconditionally from windows.h,
203  * so we do not want to include windows.h if we want winsock2.h
204  */
205 #if defined(_WINDOWS) && !defined(__CYGWIN__)
206 
207 #ifndef __GNUC__
208 #pragma warning (disable : 4100)	/* unreferenced formal parameter */
209 #pragma warning (disable : 4127)	/* conditional expression is constant */
210 #pragma warning (disable : 4201)	/* nameless struct/union */
211 #pragma warning (disable : 4214)	/* bit field types other than int */
212 #pragma warning (disable : 4310)	/* cast truncates constant value */
213 #pragma warning (disable : 4514)	/* unreferenced inline function has been removed */
214 #pragma warning (disable : 4996)	/* This function or variable may be unsafe. ... */
215 #endif
216 
217 #if defined(USE_WINSOCK2_H) && (_MSC_VER >= 1300) && (_MSC_VER < 1400)
218 #include <winsock2.h>		/* includes windows.h, in turn windef.h */
219 #else
220 #include <windows.h>		/* #include "windef.h" */
221 #endif
222 
223 #define BOOLEAN_DEFINED
224 
225 #if !_WIN_CC			/* 1999/09/29 (Wed) 22:00:53 */
226 #include <dos.h>
227 #endif
228 
229 #if !defined(__MINGW32__)
230 #undef sleep			/* 1998/06/23 (Tue) 16:54:53 */
231 extern void sleep(unsigned __seconds);
232 #endif
233 
234 #define popen _popen
235 #define pclose _pclose
236 
237 #if defined(_MSC_VER) && (_MSC_VER > 0)
238 typedef unsigned short mode_t;
239 #endif
240 
241 #endif /* _WINDOWS */
242 
243 #if defined(USE_DEFAULT_COLORS) && !defined(HAVE_USE_DEFAULT_COLORS)
244     /* if we don't have use_default_colors() */
245 #  undef USE_DEFAULT_COLORS
246 #endif
247 
248 #ifndef USE_COLOR_STYLE
249     /* it's useless for such setup */
250 #  define NO_EMPTY_HREFLESS_A
251 #endif
252 
253 #if  defined(__EMX__) || defined(WIN_EX) || defined(HAVE_POPEN)
254 # if 0 /* <20111014043246.C79038@mail101.his.com> */
255 #  define CAN_CUT_AND_PASTE
256 # endif
257 #endif
258 
259 #if defined(USE_SLANG) || (defined(USE_COLOR_STYLE) && defined(__EMX__))
260 #  define USE_BLINK
261 #endif
262 
263 #if defined(DOSPATH) || defined(__EMX__)
264 #  define USE_DOS_DRIVES	/* we allow things like "c:" in paths */
265 #endif
266 
267 #if defined(UNIX)
268 #  if (defined(__BEOS__) || defined(__CYGWIN__) || defined(__DJGPP__) || defined(__EMX__) || defined(__MINGW32__))
269 #    define SINGLE_USER_UNIX	/* well, at least they try */
270 #  else
271 #    define MULTI_USER_UNIX
272 #  endif
273 #endif
274 
275 /*
276 
277   ERROR TYPE
278 
279    This is passed back when streams are aborted. It might be nice to have some structure
280    of error messages, numbers, and recursive pointers to reasons.  Curently this is a
281    placeholder for something more sophisticated.
282 
283  */
284 typedef void *HTError;		/* Unused at present -- best definition? */
285 
286 /*
287 
288 Standard C library for malloc() etc
289 
290  */
291 #ifdef HAVE_STDLIB_H
292 #include <stdlib.h>
293 #endif
294 
295 #ifndef EXIT_SUCCESS
296 #define EXIT_SUCCESS 0
297 #endif
298 
299 #ifndef EXIT_FAILURE
300 #define EXIT_FAILURE 1
301 #endif
302 
303 #ifdef __EMX__
304 #include <unistd.h>		/* should be re-include protected under EMX */
305 #define getcwd _getcwd2
306 #define chdir _chdir2
307 #endif
308 
309 #ifdef vax
310 #ifdef unix
311 #define ultrix			/* Assume vax+unix=ultrix */
312 #endif /* unix */
313 #endif /* vax */
314 
315 #ifndef VMS
316 #ifndef ultrix
317 
318 #ifdef NeXT
319 #include <libc.h>		/* NeXT */
320 #endif /* NeXT */
321 
322 #else /* ultrix: */
323 
324 #include <malloc.h>
325 #include <memory.h>
326 
327 #endif /* !ultrix */
328 #else /* VMS: */
329 
330 #include <unixlib.h>
331 #if defined(VAXC) && !defined(__DECC)
332 #define malloc	VAXC$MALLOC_OPT
333 #define calloc	VAXC$CALLOC_OPT
334 #define free	VAXC$FREE_OPT
335 #define cfree	VAXC$CFREE_OPT
336 #define realloc	VAXC$REALLOC_OPT
337 #endif /* VAXC && !__DECC */
338 
339 #endif /* !VMS */
340 
341 #ifndef NULL
342 #define NULL ((void *)0)
343 #endif
344 
345 #define isEmpty(s)   ((s) == 0 || *(s) == 0)
346 #define non_empty(s) !isEmpty(s)
347 
348 #define NonNull(s) (((s) != 0) ? s : "")
349 #define NONNULL(s) (((s) != 0) ? s : "(null)")
350 
351 /* array/table size */
352 #define	TABLESIZE(v)	(sizeof(v)/sizeof(v[0]))
353 
354 #define	typecalloc(cast)		(cast *)calloc((size_t)1, sizeof(cast))
355 #define	typecallocn(cast,ntypes)	(cast *)calloc((size_t)(ntypes),sizeof(cast))
356 
357 #define typeRealloc(cast,ptr,ntypes)    (cast *)realloc(ptr, (size_t)(ntypes)*sizeof(cast))
358 
359 #define typeMalloc(cast)                (cast *)malloc(sizeof(cast))
360 #define typeMallocn(cast,ntypes)        (cast *)malloc((size_t)(ntypes)*sizeof(cast))
361 
362 /*
363 
364 OFTEN USED INTEGER MACROS
365 
366   Min and Max functions
367 
368  */
369 #ifndef HTMIN
370 #define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
371 #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
372 #endif
373 /*
374 
375 Booleans
376 
377  */
378 /* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
379 /* #define GOOD(status) ((status)38;1)   VMS style status: test bit 0         */
380 /* #define BAD(status)  (!GOOD(status))  Bit 0 set if OK, otherwise clear   */
381 
382 #ifndef _WINDOWS
383 #ifndef BOOLEAN_DEFINED
384 typedef char BOOLEAN;		/* Logical value */
385 
386 #ifndef CURSES
387 #ifndef TRUE
388 #define TRUE    (BOOLEAN)1
389 #define FALSE   (BOOLEAN)0
390 #endif
391 #endif /*  CURSES  */
392 #endif /*  BOOLEAN_DEFINED */
393 #define BOOLEAN_DEFINED
394 #endif /* _WINDOWS */
395 
396 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
397 /* it declares BOOL/BOOLEAN as BYTE/int */
398 #else
399 #ifndef BOOL
400 #define BOOL BOOLEAN
401 #endif
402 #endif
403 
404 #ifndef YES
405 #define YES (BOOLEAN)1
406 #define NO (BOOLEAN)0
407 #endif
408 
409 #define STRING1PTR const char *
410 #define STRING2PTR const char * const *
411 
412 extern BOOL LYOutOfMemory;	/* Declared in LYexit.c - FM */
413 
414 #define TCP_PORT 80		/* Allocated to http by Jon Postel/ISI 24-Jan-92 */
415 #define OLD_TCP_PORT 2784	/* Try the old one if no answer on 80 */
416 #define DNP_OBJ 80		/* This one doesn't look busy, but we must check */
417 			/* That one was for decnet */
418 
419 /*      Inline Function WHITE: Is character c white space? */
420 /*      For speed, include all control characters */
421 
422 #define WHITE(c) ((UCH(TOASCII(c))) <= 32)
423 
424 /*     Inline Function LYIsASCII: Is character c a traditional ASCII
425  *     character (i.e. <128) after converting from host character set.  */
426 
427 #define LYIsASCII(c) (TOASCII(UCH(c)) < 128)
428 
429 /*
430 
431 Success (>=0) and failure (<0) codes
432 
433 Some of the values are chosen to be HTTP-like, but status return values
434 are generally not the response status from any specific protocol.
435 
436  */
437 
438 #define HT_PARSER_OTHER_CONTENT  701	/* tells SGML to change content model */
439 #define HT_PARSER_REOPEN_ELT     700	/* tells SGML parser to keep tag open */
440 #define HT_REDIRECTING           399
441 #define HT_PARTIAL_CONTENT       206	/* Partial Content */
442 #define HT_LOADED                200	/* Instead of a socket */
443 
444 #define HT_OK                      0	/* Generic success */
445 
446 #define HT_ERROR                  -1	/* Generic failure */
447 #define HT_CANNOT_TRANSLATE       -4
448 #define HT_BAD_EOF               -12	/* Premature EOF */
449 #define HT_NO_CONNECTION         -99	/* ERR no connection available - */
450 #define HT_NO_DATA              -204	/* OK but no data was loaded - */
451 					/* possibly other app started or forked */
452 #define HT_NO_ACCESS            -401	/* Access not available */
453 #define HT_FORBIDDEN            -403	/* Access forbidden */
454 #define HT_NOT_ACCEPTABLE       -406	/* Not Acceptable */
455 #define HT_H_ERRNO_VALID        -800	/* see h_errno for resolver error */
456 #define HT_INTERNAL             -900	/* Weird -- should never happen. */
457 #define HT_INTERRUPTED        -29998
458 #define HT_NOT_LOADED         -29999
459 
460 #ifndef va_arg
461 #  include <stdarg.h>
462 #endif
463 
464 #define LYva_start(ap,format) va_start(ap,format)
465 
466 /*
467  * GCC can be told that some functions are like printf (and do type-checking on
468  * their parameters).
469  */
470 #ifndef GCC_PRINTFLIKE
471 #if defined(GCC_PRINTF) && !defined(printf) && !defined(HAVE_LIBUTF8_H)
472 #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
473 #else
474 #define GCC_PRINTFLIKE(fmt,var)	/*nothing */
475 #endif
476 #endif
477 
478 #include <HTString.h>		/* String utilities */
479 
480 /*
481 
482 Out Of Memory checking for malloc() return:
483 
484  */
485 #ifndef __FILE__
486 #define __FILE__ ""
487 #define __LINE__ ""
488 #endif
489 
490 #include <LYexit.h>
491 
492 /*
493  * Upper- and Lowercase macros
494  *
495  * The problem here is that toupper(x) is not defined officially unless
496  * isupper(x) is.  These macros are CERTAINLY needed on #if defined(pyr) ||
497  * define(mips) or BDSI platforms.  For safefy, we make them mandatory.
498  *
499  * Note: Pyramid and Mips can't uppercase non-alpha.
500  */
501 #include <ctype.h>
502 #include <string.h>
503 
504 #ifndef TOLOWER
505 
506 #ifdef USE_ASCII_CTYPES
507 
508 #define TOLOWER(c) ascii_tolower(UCH(c))
509 #define TOUPPER(c) ascii_toupper(UCH(c))
510 #define ISUPPER(c) ascii_isupper(UCH(c))
511 
512 #else
513 
514 #define TOLOWER(c) (isupper(UCH(c)) ? tolower(UCH(c)) : UCH(c))
515 #define TOUPPER(c) (islower(UCH(c)) ? toupper(UCH(c)) : UCH(c))
516 #define ISUPPER(c) (isupper(UCH(c)))
517 
518 #endif
519 
520 #endif /* TOLOWER */
521 
522 #define FREE(x)    {if (x != 0) {free((char *)x); x = NULL;}}
523 
524 /*
525 
526 The local equivalents of CR and LF
527 
528    We can check for these after net ascii text has been converted to the local
529    representation.  Similarly, we include them in strings to be sent as net ascii after
530    translation.
531 
532  */
533 #define LF   FROMASCII('\012')	/* ASCII line feed LOCAL EQUIVALENT */
534 #define CR   FROMASCII('\015')	/* Will be converted to ^M for transmission */
535 
536 /*
537  * Debug message control.
538  */
539 #ifdef NO_LYNX_TRACE
540 #define WWW_TraceFlag   0
541 #define WWW_TraceMask   0
542 #define LYTraceLogFP    0
543 #else
544 extern BOOLEAN WWW_TraceFlag;
545 extern int WWW_TraceMask;
546 #endif
547 
548 #define TRACE           (WWW_TraceFlag)
549 #define TRACE_bit(n)    (TRACE && (WWW_TraceMask & (1 << n)) != 0)
550 #define TRACE_SGML      (TRACE_bit(0))
551 #define TRACE_STYLE     (TRACE_bit(1))
552 #define TRACE_TRST      (TRACE_bit(2))
553 #define TRACE_CFG       (TRACE_bit(3))
554 #define TRACE_BSTRING   (TRACE_bit(4))
555 #define TRACE_COOKIES   (TRACE_bit(5))
556 #define TRACE_CHARSETS  (TRACE_bit(6))
557 #define TRACE_GRIDTEXT  (TRACE_bit(7))
558 #define TRACE_TIMING    (TRACE_bit(8))
559 
560 /*
561  * Get printing/scanning formats.
562  */
563 #if defined(HAVE_INTTYPES_H)
564 #include <inttypes.h>
565 #endif
566 
567 /*
568  * Printing/scanning-formats for "off_t", as well as cast needed to fit.
569  */
570 #if defined(HAVE_LONG_LONG) && defined(HAVE_INTTYPES_H) && defined(SIZEOF_OFF_T)
571 #if (SIZEOF_OFF_T == 8) && defined(PRId64)
572 
573 #define PRI_off_t	PRId64
574 #define SCN_off_t	SCNd64
575 #define CAST_off_t(n)	(int64_t)(n)
576 
577 #elif (SIZEOF_OFF_T == 4) && defined(PRId32)
578 
579 #define PRI_off_t	PRId32
580 #define SCN_off_t	SCNd32
581 
582 #if (SIZEOF_INT == 4)
583 #define CAST_off_t(n)	(int)(n)
584 #elif (SIZEOF_LONG == 4)
585 #define CAST_off_t(n)	(long)(n)
586 #else
587 #define CAST_off_t(n)	(int32_t)(n)
588 #endif
589 
590 #endif
591 #endif
592 
593 #ifndef PRI_off_t
594 #if defined(HAVE_LONG_LONG) && (SIZEOF_OFF_T > SIZEOF_LONG)
595 #define PRI_off_t	"lld"
596 #define SCN_off_t	"lld"
597 #define CAST_off_t(n)	(long long)(n)
598 #else
599 #define PRI_off_t	"ld"
600 #define SCN_off_t	"ld"
601 #define CAST_off_t(n)	(long)(n)
602 #endif
603 #endif
604 
605 /*
606  * Printing-format for "time_t", as well as cast needed to fit.
607  */
608 #if defined(HAVE_LONG_LONG) && defined(HAVE_INTTYPES_H) && defined(SIZEOF_TIME_T)
609 #if (SIZEOF_TIME_T == 8) && defined(PRId64)
610 
611 #define PRI_time_t	PRId64
612 #define SCN_time_t	SCNd64
613 #define CAST_time_t(n)	(int64_t)(n)
614 
615 #elif (SIZEOF_TIME_T == 4) && defined(PRId32)
616 
617 #define PRI_time_t	PRId32
618 #define SCN_time_t	SCNd32
619 
620 #if (SIZEOF_INT == 4)
621 #define CAST_time_t(n)	(int)(n)
622 #elif (SIZEOF_LONG == 4)
623 #define CAST_time_t(n)	(long)(n)
624 #else
625 #define CAST_time_t(n)	(int32_t)(n)
626 #endif
627 
628 #endif
629 #endif
630 
631 #ifndef PRI_time_t
632 #if defined(HAVE_LONG_LONG) && (SIZEOF_TIME_T > SIZEOF_LONG)
633 #define PRI_time_t	"lld"
634 #define SCN_time_t	"lld"
635 #define CAST_time_t(n)	(long long)(n)
636 #else
637 #define PRI_time_t	"ld"
638 #define SCN_time_t	"ld"
639 #define CAST_time_t(n)	(long)(n)
640 #endif
641 #endif
642 
643 /*
644  * Printing-format for "UCode_t".
645  */
646 #define PRI_UCode_t	"lX"
647 
648 /*
649  * Verbose-tracing.
650  */
651 #if defined(USE_VERTRACE) && !defined(LY_TRACELINE)
652 #define LY_TRACELINE __LINE__
653 #endif
654 
655 #if defined(LY_TRACELINE)
656 #define LY_SHOWWHERE fprintf( tfp, "%s: %d: ", __FILE__, LY_TRACELINE ),
657 #else
658 #define LY_SHOWWHERE		/* nothing */
659 #endif
660 
661 #define CTRACE(p)         ((void)((TRACE) && ( LY_SHOWWHERE fprintf p )))
662 #define CTRACE2(m,p)      ((void)((m)     && ( LY_SHOWWHERE fprintf p )))
663 #define tfp TraceFP()
664 #define CTRACE_SLEEP(secs) if (TRACE && LYTraceLogFP == 0) sleep((unsigned)secs)
665 #define CTRACE_FLUSH(fp)   if (TRACE) fflush(fp)
666 
667 #include <www_tcp.h>
668 
669 /*
670  * We force this include-ordering since socks.h contains redefinitions of
671  * functions that probably are prototyped via other includes.  The socks.h
672  * definitions have to be included everywhere, since they're making wrappers
673  * for the stdio functions as well as the network functions.
674  */
675 #if defined(USE_SOCKS5) && !defined(DONT_USE_SOCKS5)
676 #define SOCKS4TO5		/* turn on the Rxxxx definitions used in Lynx */
677 #include <socks.h>
678 
679 /*
680  * The AIX- and SOCKS4-specific definitions in socks.h are inconsistent.
681  * Repair them so they're consistent (and usable).
682  */
683 #if defined(_AIX) && !defined(USE_SOCKS4_PREFIX)
684 #undef  Raccept
685 #define Raccept       accept
686 #undef  Rgetsockname
687 #define Rgetsockname  getsockname
688 #undef  Rgetpeername
689 #define Rgetpeername  getpeername
690 #endif
691 
692 /*
693  * Workaround for order-of-evaluation problem with gcc and socks5 headers
694  * which breaks the Rxxxx names by attaching the prefix twice:
695  */
696 #ifdef INCLUDE_PROTOTYPES
697 #undef  Raccept
698 #undef  Rbind
699 #undef  Rconnect
700 #undef  Rlisten
701 #undef  Rselect
702 #undef  Rgetpeername
703 #undef  Rgetsockname
704 #define Raccept       accept
705 #define Rbind         bind
706 #define Rconnect      connect
707 #define Rgetpeername  getpeername
708 #define Rgetsockname  getsockname
709 #define Rlisten       listen
710 #define Rselect       select
711 #endif
712 
713 #endif /* USE_SOCKS5 */
714 
715 #define SHORTENED_RBIND		/* FIXME: do this in configure-script */
716 
717 #ifdef USE_SSL
718 
719 #define free_func free__func
720 
721 #ifdef USE_OPENSSL_INCL
722 #include <openssl/ssl.h>
723 #include <openssl/crypto.h>
724 #include <openssl/rand.h>
725 #include <openssl/err.h>
726 
727 #else
728 
729 #if defined(USE_GNUTLS_FUNCS)
730 #include <tidy_tls.h>
731 #define USE_GNUTLS_INCL 1	/* do this for the ".c" ifdefs */
732 #elif defined(USE_GNUTLS_INCL)
733 #include <gnutls/openssl.h>
734 /*
735  * GNUTLS' implementation of OpenSSL is very incomplete and rudimentary.
736  * For a start, let's make it compile (TD - 2003/4/13).
737  */
738 #ifndef SSL_VERIFY_PEER
739 #define SSL_VERIFY_PEER			0x01
740 #endif
741 #else
742 
743 #ifdef USE_NSS_COMPAT_INCL
744 #include <nss_compat_ossl/nss_compat_ossl.h>
745 
746 #else /* assume SSLeay */
747 #include <ssl.h>
748 #include <crypto.h>
749 #include <rand.h>
750 #include <err.h>
751 #endif
752 #endif
753 #endif /* USE_OPENSSL_INCL */
754 
755 #undef free_func
756 #endif /* USE_SSL */
757 
758 #ifdef HAVE_BSD_STDLIB_H
759 #include <bsd/stdlib.h>		/* prototype for arc4random.h */
760 #elif defined(HAVE_BSD_RANDOM_H)
761 #include <bsd/random.h>		/* prototype for arc4random.h */
762 #endif
763 
764 #ifdef HAVE_LIBDMALLOC
765 #include <dmalloc.h>		/* Gray Watson's library */
766 #define show_alloc() dmalloc_log_unfreed()
767 #endif
768 
769 #ifdef HAVE_LIBDBMALLOC
770 #include <dbmalloc.h>		/* Conor Cahill's library */
771 #define show_alloc() malloc_dump(fileno(stderr))
772 #endif
773 
774 #ifndef show_alloc
775 #define show_alloc()		/* nothing */
776 #endif
777 
778 #include <userdefs.h>
779 
780 #ifdef __cplusplus
781 extern "C" {
782 #endif
783 #ifndef TOLOWER
784 #ifdef USE_ASCII_CTYPES
785     extern int ascii_toupper(int);
786     extern int ascii_tolower(int);
787     extern int ascii_isupper(int);
788 #endif
789 #endif
790 
791     extern FILE *TraceFP(void);
792 
793 #ifdef USE_SSL
794     extern SSL *HTGetSSLHandle(void);
795     extern void HTSSLInitPRNG(void);
796     extern int HTGetSSLCharacter(void *handle);
797 #endif				/* USE_SSL */
798 
799 #ifdef __cplusplus
800 }
801 #endif
802 #endif				/* HTUTILS_H */
803