File: HTUtils.html

package info (click to toggle)
cern-httpd 3.0A-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 5,392 kB
  • ctags: 6,554
  • sloc: ansic: 37,902; makefile: 1,746; perl: 535; csh: 167; sh: 143
file content (351 lines) | stat: -rw-r--r-- 9,817 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<HTML>
<HEAD>
<TITLE>Utility macros for the W3 code library</TITLE>
<NEXTID N="z2">
</HEAD>
<BODY>
<H1>Macros for general use</H1>

This module is a very basic module of the <A HREF="Overview.html">CERN
Common Code Library</A> See also: the system dependent file<A NAME="z0"
HREF="tcp.html">"tcp.h"</A> for system specific information.

<PRE>
#ifndef HTUTILS_H
#define HTUTILS_H

#ifndef DEBUG
#define DEBUG	/* No one ever turns this off as trace is too important */
#endif		/* Keep option for really small memory applications too */

#ifdef _WINDOWS				/* SCW */
#include "windef.h"
#define BOOLEAN_DEFINED
#endif

#ifdef SHORT_NAMES
#define WWW_TraceFlag HTTrFlag
#endif

#ifndef STDIO_H
#include &lt;stdio.h>
#define STDIO_H
#endif
</PRE>

<H2>Debug message control</H2>

This is the global flag for setting the TRACE options.

<PRE>
extern int WWW_TraceFlag;		     /* Global flag for all W3 trace */
</PRE>

The verbose mode is no longer a simple boolean but a bit field so that it is
possible to see parts of the output messages. The <EM>TRACE</EM> define still
outputs all messages if verbose mode is active, but in addition the following
TRACE defines have been made:

<PRE>
typedef enum _HTTraceFlags {
    SHOW_SGML_TRACE	= 0xF,				/*		1111 */
    SHOW_PROTOCOL_TRACE = 0xF0,				/* 	   1111.0000 */
    SHOW_URI_TRACE	= 0x300,			/* 	11.0000.0000 */
    SHOW_ANCHOR_TRACE	= 0xC00,			/*   11.00.0000.0000 */
    SHOW_ALL_TRACE	= 0xFFF				/*   11.11.1111.1111 */
} HTTraceFlags;
</PRE>

The flags are made so that they can serve as a group flag for correlated
trace messages, e.g. showing messages for SGML and HTML at the same time. 

<PRE>
#ifdef DEBUG
#define TRACE		(WWW_TraceFlag)
#define SGML_TRACE	(WWW_TraceFlag & SHOW_SGML_TRACE)
#define PROT_TRACE	(WWW_TraceFlag & SHOW_PROTOCOL_TRACE)
#define URI_TRACE	(WWW_TraceFlag & SHOW_URI_TRACE)
#define ANCH_TRACE	(WWW_TraceFlag & SHOW_ANCHOR_TRACE)
#define PROGRESS(str)	printf(str)
#else
#define TRACE		0
#define SGML_TRACE	0
#define PROT_TRACE	0
#define URI_TRACE	0
#define ANCH_TRACE	0
#define PROGRESS(str)	/* nothing for now */
#endif
</PRE>

<EM><B>Note: </B> The CTRACE flag might interfere with other if () else
constructions in the code</EM>

<PRE>
#define CTRACE if(TRACE) fprintf
#define tfp stderr
</PRE>


<H2>Error type</H2>

THIS IS NOW OBSOLETE AND WILL BE REMOVED IN FUTURE RELEASES <P>

This is passed back when streams
are aborted. It might be nice to
have some structure of error messages,
numbers, and recursive pointers to
reasons. Curently this is a placeholder
for something more sophisticated.
<PRE>typedef void * HTError;			/* Unused at present -- best definition? */

</PRE>
<H2>Standard C library for malloc() etc</H2>

Replace memory allocation and free C RTL functions
with VAXC$xxx_OPT altrenatives for VAXC (but not DECC)
on VMS. This makes a big performance difference. (Foteos
Macrides).

<PRE>#ifdef vax
#ifdef unix
#define ultrix	/* Assume vax+unix=ultrix */
#endif
#endif

#ifndef VMS
#ifndef ultrix
#ifdef NeXT
#include &lt;libc.h>	/* NeXT */
#endif
#ifndef Mips
#ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
#include &lt;stdlib.h>	/* ANSI */
#endif
#else /* Mips */
#define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
#define S_ISREG(m)      (((m)&S_IFMT) == S_IFREG)
#endif /* Mips */
#else /* ultrix */
#include &lt;malloc.h>
#include &lt;memory.h>
#include &lt;stdio.h>
#include &lt;stdlib.h>   /* ANSI */   /* BSN */
#endif

#else	/* VMS */
#include &lt;stdio.h>
#include &lt;stdlib.h>
#include &lt;unixlib.h>
#include &lt;ctype.h>
#if defined(VAXC) && !defined(__DECC)
#define malloc	VAXC$MALLOC_OPT
#define calloc	VAXC$CALLOC_OPT
#define free	VAXC$FREE_OPT
#define cfree	VAXC$CFREE_OPT
#define realloc	VAXC$REALLOC_OPT
#endif /* VAXC but not DECC */
#define unlink remove
#define gmtime localtime
#include &lt;stat.h>
#define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
#define S_ISREG(m)      (((m)&S_IFMT) == S_IFREG)
#define putenv HTVMS_putenv
#endif

</PRE>
<H2>Macros for declarations</H2>
<PRE>#define PUBLIC			/* Accessible outside this module     */
#define PRIVATE static		/* Accessible only within this module */

#ifdef __STDC__
#define CONST const		/* "const" only exists in STDC */
#define NOPARAMS (void)
#define PARAMS(parameter_list) parameter_list
#define NOARGS (void)
#define ARGS1(t,a) \
		(t a)
#define ARGS2(t,a,u,b) \
		(t a, u b)
#define ARGS3(t,a,u,b,v,c) \
		(t a, u b, v c)
#define ARGS4(t,a,u,b,v,c,w,d) \
		(t a, u b, v c, w d)
#define ARGS5(t,a,u,b,v,c,w,d,x,e) \
		(t a, u b, v c, w d, x e)
#define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
		(t a, u b, v c, w d, x e, y f)
#define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
		(t a, u b, v c, w d, x e, y f, z g)
#define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
		(t a, u b, v c, w d, x e, y f, z g, s h)
#define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
		(t a, u b, v c, w d, x e, y f, z g, s h, r i)
#define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
		(t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)

#else  /* not ANSI */

#ifndef _WINDOWS
#define CONST
#endif
#define NOPARAMS ()
#define PARAMS(parameter_list) ()
#define NOARGS ()
#define ARGS1(t,a) (a) \
		t a;
#define ARGS2(t,a,u,b) (a,b) \
		t a; u b;
#define ARGS3(t,a,u,b,v,c) (a,b,c) \
		t a; u b; v c;
#define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
		t a; u b; v c; w d;
#define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
		t a; u b; v c; w d; x e;
#define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
		t a; u b; v c; w d; x e; y f;
#define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
		t a; u b; v c; w d; x e; y f; z g;
#define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) (a,b,c,d,e,f,g,h) \
		t a; u b; v c; w d; x e; y f; z g; s h;
#define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) (a,b,c,d,e,f,g,h,i) \
		t a; u b; v c; w d; x e; y f; z g; s h; r i;
#define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) (a,b,c,d,e,f,g,h,i,j) \
		t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
		
	
#endif /* __STDC__ (ANSI) */

#ifndef NULL
#define NULL ((void *)0)
#endif

</PRE>
<H2>Booleans</H2>
<PRE>/* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
/* #define GOOD(status) ((status)38;1)	 VMS style status: test bit 0	      */
/* #define BAD(status)  (!GOOD(status))	 Bit 0 set if OK, otherwise clear   */

#ifndef _WINDOWS
#ifndef BOOLEAN_DEFINED
	typedef char	BOOLEAN;		/* Logical value */
#ifndef CURSES
#ifndef TRUE
#define TRUE	(BOOLEAN)1
#define	FALSE	(BOOLEAN)0
#endif
#endif	 /*  CURSES  */
#endif   /* _WINDOWS */
#define BOOLEAN_DEFINED
#endif

#ifndef BOOL
#define BOOL BOOLEAN
#endif
#ifndef YES
#define YES             (BOOL)1
#define NO              (BOOL)0
#endif

#ifndef HTMIN 
#define HTMIN(a,b) ((a) &lt;= (b) ? (a) : (b))
#define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
#endif

#define TCP_PORT 80	/* Allocated to http by Jon Postel/ISI 24-Jan-92 */
#define OLD_TCP_PORT 2784	/* Try the old one if no answer on 80 */
#define DNP_OBJ 80	/* This one doesn't look busy, but we must check */
			/* That one was for decnet */

</PRE>
<H2>Return Codes for Protocol Modules</H2>

Theese are the codes returned from the protocol modules. Success (&gt;=0) and
failure (&lt;0) codes
<PRE>
#define HT_NO_DATA		-9999	/* OK but no data was loaded */
					/* Typically, other app started */
#define HT_INTERRUPTED 		-29998	/* Note the negative value! */
#define HT_LOADED		 29999	/* Instead of a socket */
#define HT_REDIRECTION_ON_FLY	 29998	/* Redo the retrieve with a new URL */

#define HT_OK		  0		/* Generic success*/
#define HT_NO_ACCESS	-10		/* Access not available */
#define HT_FORBIDDEN	-11		/* Access forbidden */
#define HT_INTERNAL	-12		/* Weird -- should never happen. */
#define HT_BAD_EOF	-13		/* Premature EOF */


#include "HTString.h"  	/* String utilities */

#ifdef __STDC__
#include &lt;stdarg.h>
#else
#include &lt;varargs.h>
#endif

#ifdef CURSES
	/* htbrowse.c; */
#ifdef ULTRIX      /* or DECSTATION */
#include &lt;cursesX.h>	/* Extended curses under X. Only decent one :lou. */
#else
#include &lt;curses.h>
#endif /* ULTRIX */
	extern        WINDOW  *w_top, *w_text, *w_prompt;
	extern        void    user_message PARAMS((const char *fmt, ...));
	extern        void    prompt_set PARAMS((CONST char * msg));
	extern        void    prompt_count PARAMS((long kb));
#else
#define user_message printf
#endif

</PRE>
<H2>Out Of Memory checking for malloc()
return:</H2>
<PRE>#ifndef __FILE__
#define __FILE__ ""
#define __LINE__ ""
#endif

#define outofmem(file, func) \
 { fprintf(stderr, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
  exit(1);}
/* extern void outofmem PARAMS((const char *fname, const char *func)); */


</PRE>
<H3>who put these in and what are they
anyway?</H3>
<PRE>#ifdef THEY_WILL_BE_REMOVED
extern void msg_init PARAMS((int height));
extern void msg_printf PARAMS((int y, const char *fmt, ...));
extern void msg_exit PARAMS((int wait_for_key));
#endif

</PRE>
<H2>Upper- and Lowercase macros</H2>The problem here is that toupper(x)
is not defined officially unless
isupper(x) is.  These macros are
CERTAINLY needed on #if defined(pyr)
|| define(mips) or BDSI platforms.
For safefy, we make them mandatory.
<PRE>#include &lt;ctype.h>

#ifndef TOLOWER
  /* Pyramid and Mips can't uppercase non-alpha */
#define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
#define TOUPPER(c) (islower(c) ? toupper(c) : (c))
#endif /* ndef TOLOWER */

</PRE>
<H2>The local equivalents of CR and LF</H2>We can check for these after net
ascii text has been converted to
the local representation. Similarly,
we include them in strings to be
sent as net ascii after translation.
<PRE>#define LF   FROMASCII('\012')  /* ASCII line feed LOCAL EQUIVALENT */
#define CR   FROMASCII('\015')  /* Will be converted to ^M for transmission */

#endif /* HTUTILS_H */

</PRE>end of utilities</BODY>
</HTML>