Annotation of libwww/Library/src/HTErrorMsg.c, revision 2.2
2.1 frystyk 1: /* Error Output Module
2: ** ===================
3: **
4: ** This module contains the error / information generating function
5: ** HTErrorMsg() so taht it can be overwritten by smart browsers and
6: ** servers.
7: **
8: ** History:
9: ** 05 May 94 Written by Henrik Frystyk, frystyk@dxcern.cern.ch
10: */
11:
12: /* Library include files */
13: #include "HTUtils.h"
14: #include "HTAccess.h"
15: #include "HTAlert.h"
16: #include "HTTCP.h"
17: #include "HTChunk.h"
18: #include "HTError.h" /* Implemented here */
19:
20:
21: /* HTErrorMsg
22: **
23: ** Default function that creates an error message using HTAlert() to
24: ** put out the contents of the error_stack messages. Furthermore, the
25: ** error_info structure contains a name of a help file that might be put
26: ** up as a link. This file can then be multi-linguistic.
27: **
28: ** This function might be overwritten by a smart server or client.
29: */
30: PUBLIC void HTErrorMsg ARGS1(HTRequest *, request)
31: {
32: HTList *cur = request->error_stack;
33: BOOL highest = YES;
34: HTChunk *chunk;
35: HTErrorInfo *pres;
36: if (!request) {
37: if (TRACE) fprintf(stderr, "HTErrorMsg.. Bad argument!\n");
38: return;
39: }
40:
41: /* This check is only necessary if the error message is put down the
42: stream, because we have to know if a stream has been put up and/or
43: taken down again. Here it is only put as an example */
44: if (request->error_block) {
45: if (TRACE) fprintf(stderr, "HTErrorMsg.. No messages are printed as no stream is available.\n");
46: return;
47: }
48:
49: /* Output messages */
50: chunk = HTChunkCreate(128);
51: while ((pres = (HTErrorInfo *) HTList_nextObject(cur))) {
52:
53: /* Check if we are going to show the message */
54: if ((!pres->ignore || HTErrorShowMask & HT_ERR_SHOW_IGNORE) &&
55: (HTErrorShowMask & pres->severity)) {
56:
57: /* Output code number */
58: if (highest) { /* If first time through */
59: if (TRACE)
60: fprintf(stderr,
61: "HTError..... Generating message.\n");
62:
63: /* Output title */
64: if (pres->severity == ERR_WARNING)
65: HTChunkPuts(chunk, "Warning ");
66: else if (pres->severity == ERR_NON_FATAL)
67: HTChunkPuts(chunk, "Non Fatal Error ");
68: else if (pres->severity == ERR_FATAL)
69: HTChunkPuts(chunk, "Fatal Error ");
70: else if (pres->severity == ERR_INFO)
71: HTChunkPuts(chunk, "Information ");
72: else {
73: if (TRACE)
74: fprintf(stderr, "HTError..... Unknown Classification of Error (%d)...\n", pres->severity);
75: HTChunkFree(chunk);
76: return;
77: }
78:
79: /* Only output error code if it is a real HTTP code */
80: if (pres->element < HTERR_HTTP_CODES_END) {
81: char codestr[10];
82: sprintf(codestr, "%d ", error_info[pres->element].code);
83: HTChunkPuts(chunk, codestr);
84: }
85: highest = NO;
86: } else
87: HTChunkPuts(chunk, "\nReason: ");
88:
89: /* Output error message */
90: if (pres->element != HTERR_SYSTEM) {
91: HTChunkPuts(chunk, error_info[pres->element].msg);
92: HTChunkPutc(chunk, ' ');
93: }
94:
95: /* Output parameters */
96: if (pres->par && HTErrorShowMask & HT_ERR_SHOW_PARS) {
97: int cnt;
98: char ch;
99: for (cnt=0; cnt<pres->par_length; cnt++) {
100: ch = *((char *)(pres->par)+cnt);
101: if (ch < 0x20 || ch >= 0x7F)
102: HTChunkPutc(chunk, '#'); /* Can't print real content */
103: else
104: HTChunkPutc(chunk, ch);
105: }
106: }
107:
108: /* Output location */
109: if (pres->where && HTErrorShowMask & HT_ERR_SHOW_LOCATION) {
110: HTChunkPuts(chunk, "This occured in ");
111: HTChunkPuts(chunk, pres->where);
112: HTChunkPutc(chunk, '\n');
113: }
114:
115: /* We don't want the message more than once */
116: HTErrorIgnore(request, pres->handle);
117:
118: /* If we only are going to show the higest entry */
119: if (HTErrorShowMask & HT_ERR_SHOW_FIRST)
120: break;
121: }
122: }
123: HTChunkPutc(chunk, '\n');
124: HTChunkTerminate(chunk);
125: if (chunk->size > 2)
126: HTAlert(chunk->data);
127: HTChunkFree(chunk);
128: return;
129: }
130:
Webmaster