File: HTErrorMsg.c

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 (130 lines) | stat: -rw-r--r-- 3,778 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
/*			Error Output Module
**			===================
**
**	This module contains the error / information generating function 
**	HTErrorMsg() so taht it can be overwritten by smart browsers and
**	servers.
**
** History:
**  	05 May 94	Written by Henrik Frystyk, frystyk@dxcern.cern.ch
*/

/* Library include files */
#include "HTUtils.h"
#include "HTAccess.h"
#include "HTAlert.h"
#include "HTTCP.h"
#include "HTChunk.h"
#include "HTError.h"					 /* Implemented here */


/*								HTErrorMsg
**
**	Default function that creates an error message using HTAlert() to
**	put out the contents of the error_stack messages. Furthermore, the
**	error_info structure contains a name of a help file that might be put
**	up as a link. This file can then be multi-linguistic.
**
**	This function might be overwritten by a smart server or client.
*/
PUBLIC void HTErrorMsg ARGS1(HTRequest *, request)
{
    HTList *cur = request->error_stack;
    BOOL highest = YES;
    HTChunk *chunk;
    HTErrorInfo *pres;
    if (!request) {
	if (TRACE) fprintf(stderr, "HTErrorMsg.. Bad argument!\n");
	return;
    }

    /* This check is only necessary if the error message is put down the
       stream, because we have to know if a stream has been put up and/or
       taken down again. Here it is only put as an example */
    if (request->error_block) {
	if (TRACE) fprintf(stderr, "HTErrorMsg.. No messages are printed as no stream is available.\n");
	return;
    }

    /* Output messages */
    chunk = HTChunkCreate(128);
    while ((pres = (HTErrorInfo *) HTList_nextObject(cur))) {

	/* Check if we are going to show the message */
	if ((!pres->ignore || HTErrorShowMask & HT_ERR_SHOW_IGNORE) && 
	    (HTErrorShowMask & pres->severity)) {

	    /* Output code number */
	    if (highest) {			    /* If first time through */
		if (TRACE)
		    fprintf(stderr,
			    "HTError..... Generating message.\n");
		
		/* Output title */
		if (pres->severity == ERR_WARNING)
		    HTChunkPuts(chunk, "Warning ");
		else if (pres->severity == ERR_NON_FATAL)
		    HTChunkPuts(chunk, "Non Fatal Error ");
		else if (pres->severity == ERR_FATAL)
		    HTChunkPuts(chunk, "Fatal Error ");
		else if (pres->severity == ERR_INFO)
		    HTChunkPuts(chunk, "Information ");
		else {
		    if (TRACE)
			fprintf(stderr, "HTError..... Unknown Classification of Error (%d)...\n", pres->severity);
		    HTChunkFree(chunk);
		    return;
		}

		/* Only output error code if it is a real HTTP code */
		if (pres->element < HTERR_HTTP_CODES_END) {
		    char codestr[10];
		    sprintf(codestr, "%d ", error_info[pres->element].code);
		    HTChunkPuts(chunk, codestr);
		}
		highest = NO;
	    } else
		HTChunkPuts(chunk, "\nReason: ");

	    /* Output error message */
	    if (pres->element != HTERR_SYSTEM) {
		HTChunkPuts(chunk, error_info[pres->element].msg);
		HTChunkPutc(chunk, ' ');
	    }

	    /* Output parameters */
	    if (pres->par && HTErrorShowMask & HT_ERR_SHOW_PARS) {
		int cnt;
		char ch;
		for (cnt=0; cnt<pres->par_length; cnt++) {
		    ch = *((char *)(pres->par)+cnt);
		    if (ch < 0x20 || ch >= 0x7F)
			HTChunkPutc(chunk, '#'); /* Can't print real content */
		    else
			HTChunkPutc(chunk, ch);
		}
	    }

	    /* Output location */
	    if (pres->where && HTErrorShowMask & HT_ERR_SHOW_LOCATION) {
		HTChunkPuts(chunk, "This occured in ");
		HTChunkPuts(chunk, pres->where);
		HTChunkPutc(chunk, '\n');
	    }

	    /* We don't want the message more than once */
	    HTErrorIgnore(request, pres->handle);
	    
	    /* If we only are going to show the higest entry */
	    if (HTErrorShowMask & HT_ERR_SHOW_FIRST)
		break;
	}
    }
    HTChunkPutc(chunk,  '\n');
    HTChunkTerminate(chunk);
    if (chunk->size > 2)
	HTAlert(chunk->data);
    HTChunkFree(chunk);
    return;
}