Annotation of libwww/Library/src/HTError.c, revision 2.22
2.20 frystyk 1: /* HTError.c
2: ** ERROR REPORT MODULE
3: **
4: ** (c) COPYRIGHT CERN 1994.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.1 frystyk 6: **
7: ** This is the implementaion of an error message reporting system that
8: ** reports errors occured either in a stream module (structured streams
9: ** inclusive) or in a protocol module. A list of errors are put into the
10: ** request structure and freed together with this.
11: **
12: ** History:
13: ** 05 May 94 Written by Henrik Frystyk, frystyk@dxcern.cern.ch
14: */
15:
16: /* Library include files */
2.22 ! frystyk 17: #include "tcp.h"
! 18: #include "HTUtils.h"
! 19: #include "HTString.h"
2.17 frystyk 20: #include "HTTCP.h"
2.1 frystyk 21: #include "HTError.h" /* Implemented here */
22:
23: /* Globals */
2.12 frystyk 24: PUBLIC unsigned int HTErrorShowMask = HT_ERR_SHOW_DEFAULT;
2.17 frystyk 25: PRIVATE char *HTErrorPrefix = NULL;
2.1 frystyk 26:
27: /* Type definitions and global variables etc. local to this module */
28:
29: /* All errors that are not strictly HTTP errors but originates from, e.g.,
30: the FTP protocol all have element numbers > HTERR_HTTP_CODES_END, i.e.,
2.8 frystyk 31: they should be placed after the blank line
32:
33: NOTE: codes marked `HTTP' should be future HTTP error codes.
34: */
2.4 frystyk 35: PUBLIC HTErrorMsgInfo error_info[HTERR_ELEMENTS] = {
2.15 frystyk 36: { 200, "OK", "ok.multi" },
37: { 201, "Created", "created.multi" },
38: { 202, "Accepted", "accepted.multi" },
2.22 ! frystyk 39: { 203, "Provisional Information", "partial.multi" },
2.15 frystyk 40: { 204, "No Response", "no_response.multi" },
2.22 ! frystyk 41: { 205, "Deleted", "deleted.multi" },
! 42: { 206, "Modified", "modified.multi" },
! 43: { 301, "Moved Permanently", "moved.multi" },
! 44: { 302, "Moved Temporarily", "moved.multi" },
2.15 frystyk 45: { 303, "Method", "method.multi" },
2.22 ! frystyk 46: { 304, "Not Modified", "not_modified.multi" },
! 47: { 400, "Bad Request", "bad_request.multi" },
! 48: { 401, "Unauthorized", "unauthorized.multi" },
2.15 frystyk 49: { 402, "Payment Required", "payment.multi" },
2.22 ! frystyk 50: { 403, "Forbidden", "forbidden.multi" },
! 51: { 404, "Not Found", "not_found.multi" },
! 52: { 405, "Method Not Allowed", "method.multi" },
! 53: { 406, "None Acceptable", "none.multi" },
! 54: { 407, "Proxy Authentication Required", "proxy.multi" },
! 55: { 408, "Request Timeout", "timeout.multi" },
! 56: { 500, "Internal Server Error", "internal.multi" },
! 57: { 501, "Not Implemented", "not_made.multi" },
! 58: { 502, "Bad Gateway", "bad_gate.multi" },
! 59: { 503, "Service Unavailable", "unavailable.multi" },
! 60: { 504, "Gateway Timeout", "timeout.multi" },
2.15 frystyk 61: { 0, "-------------------------", "----------------------------------" },
2.16 frystyk 62: { 0, "Can't locate remote host", "host.multi" },
63: { 0, "No host name found", "host.multi" },
2.15 frystyk 64: { 0, "FTP-server replies", "ftp.multi" },
65: { 0, "FTP-server doesn't reply", "no_server.multi" },
66: { 0, "Server timed out", "time_out.multi" },
67: { 0, "Gopher-server replies", "gopher.multi" },
68: { 0, "Data transfer interrupted", "interrupt.multi" },
2.16 frystyk 69: { 0, "Connection establishment interrupted", "interrupt.multi" },
2.15 frystyk 70: { 0, "CSO-server replies", "cso.multi" },
2.19 frystyk 71: { 0, "This is probably a HTTP server 0.9 or less","http_version" },
72: { 0, "Bad, Incomplete, or Unknown Response", "bad_reply.multi" },
73: { 0, "Unknown access authentication scheme", "control.multi" },
2.15 frystyk 74: { 0, "News-server replies", "news.multi" },
75: { 0, "Trying `ftp://' instead of `file://'. ANY OLD URL STILL USING WRONG ACCESS METHOD WILL BE OBSOLETE IN THE NEXT MAJOR RELEASE!",
76: "ftpfile.multi" },
77: { 0, "Too many redirections", "redirections.multi" },
2.19 frystyk 78: { 0, "Premature End Of File", "EOF.multi" },
2.16 frystyk 79: { 0, "Response from WAIS Server too Large - Extra lines ignored",
80: "wais.multi" },
81: { 0, "WAIS-server doesn't return any data", "wais.multi" },
2.15 frystyk 82: { 0, "Can't connect to WAIS-server", "wais.multi" },
83: { 0, "System call `%s' failed: ", "system.multi" }
2.1 frystyk 84: };
85:
86: /* ------------------------------------------------------------------------- */
87:
88: /* HTErrorAdd
89: **
90: ** Add an error message to the error list in HTRequest. `par' and `where'
2.2 frystyk 91: ** might be set to NULL. If par is a string, it is sufficient to let
2.8 frystyk 92: ** par_length be unspecified, i.e., 0. If only a part of the string is
93: ** wanted then specify a par_length inferior to strlen((char *) par).
94: ** The string is '\0' terminated automaticly.
2.2 frystyk 95: **
96: ** NOTE: See also HTErrorSysAdd for system errors
2.4 frystyk 97: **
2.22 ! frystyk 98: ** Returns always HT_ERROR
2.1 frystyk 99: */
2.4 frystyk 100: PUBLIC int HTErrorAdd ARGS7(HTRequest *, request,
101: HTErrSeverity, severity,
102: BOOL, ignore,
103: int, element,
104: void *, par,
105: unsigned int, par_length,
106: char *, where)
2.1 frystyk 107: {
108: HTErrorInfo *newError;
109: if (!request) {
2.22 ! frystyk 110: if (TRACE) fprintf(TDEST, "HTErrorAdd.. Bad argument!\n");
! 111: return HT_ERROR;
2.1 frystyk 112: }
113: if ((newError = (HTErrorInfo *) calloc(1, sizeof(HTErrorInfo))) == NULL)
114: outofmem(__FILE__, "HTErrorAdd");
2.18 frystyk 115: newError->element = (HTErrorElement) element;
2.2 frystyk 116: newError->severity = severity;
2.1 frystyk 117: newError->ignore = ignore;
2.2 frystyk 118: if (par) {
119: if (!par_length)
120: par_length = (int) strlen((char *) par);
2.1 frystyk 121: if ((newError->par = malloc(par_length+1)) == NULL)
2.10 luotonen 122: outofmem(__FILE__, "HTErrorError");
2.1 frystyk 123: memcpy(newError->par, par, par_length);
124: *(((char *) newError->par)+par_length) = '\0';
125: newError->par_length = par_length;
126: }
127: newError->where = where;
2.12 frystyk 128:
129: /* Add to the stack in the request structure */
130: if (!request->error_stack)
131: request->error_stack = HTList_new();
132: else { /* Get last object in order to find a handle */
133: HTList *cur = request->error_stack;
134: HTErrorInfo *pres = (HTErrorInfo *) HTList_nextObject(cur);
135: if (pres != NULL)
136: newError->handle = pres->handle+1;
137: }
2.1 frystyk 138: if (TRACE) {
2.22 ! frystyk 139: fprintf(TDEST, "Message..... Handle: %d\tCode: %3d\tMessage: `%s\'\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
2.12 frystyk 140: newError->handle,
2.1 frystyk 141: error_info[newError->element].code,
142: error_info[newError->element].msg,
143: newError->severity,
144: newError->par ? (char *) newError->par : "Unspecified",
145: newError->where ? newError->where : "Unspecified");
146: }
147: HTList_addObject(request->error_stack, (void *) newError);
2.22 ! frystyk 148: return HT_ERROR;
2.1 frystyk 149: }
150:
151:
2.2 frystyk 152: /* HTErrorSysAdd
153: **
154: ** Add a system error message to the error list in HTRequest. syscall
155: ** is the name of the system call, e.g. "close". The message put to the
2.22 ! frystyk 156: ** list is that corresponds to the error number passed.
2.2 frystyk 157: **
158: ** See also HTErrorAdd.
2.4 frystyk 159: **
2.22 ! frystyk 160: ** Returns always HT_ERROR
2.2 frystyk 161: */
2.22 ! frystyk 162: PUBLIC int HTErrorSysAdd ARGS5(HTRequest *, request,
2.4 frystyk 163: HTErrSeverity, severity,
2.22 ! frystyk 164: int, errornumber,
2.4 frystyk 165: BOOL, ignore,
166: char *, syscall)
2.2 frystyk 167: {
168: if (!request) {
2.22 ! frystyk 169: if (TRACE) fprintf(TDEST, "HTErrorSys.. Bad argument!\n");
! 170: return HT_ERROR;
2.2 frystyk 171: }
172: {
2.7 luotonen 173: char temp[100];
2.2 frystyk 174: char *errmsg = NULL;
2.7 luotonen 175: sprintf(temp, error_info[HTERR_SYSTEM].msg, syscall);
2.6 frystyk 176: StrAllocCopy(errmsg, temp);
2.22 ! frystyk 177: StrAllocCat(errmsg, HTErrnoString(errornumber));
2.12 frystyk 178: HTErrorAdd(request, severity, ignore, HTERR_SYSTEM, (void *) errmsg,
179: (int) strlen(errmsg), syscall);
180: free(errmsg);
2.2 frystyk 181: }
2.22 ! frystyk 182: return HT_ERROR;
2.2 frystyk 183: }
184:
185:
2.1 frystyk 186: /* HTErrorFree
187: **
188: ** Free the whole error stack from the HTRequest structure.
189: */
190: PUBLIC void HTErrorFree ARGS1(HTRequest *, request)
191: {
192: HTList *cur = request->error_stack;
193: HTErrorInfo *pres;
194: if (!request || !request->error_stack)
195: return;
196: while ((pres = (HTErrorInfo *) HTList_nextObject(cur))) {
197: FREE(pres->par);
198: free(pres);
199: }
200: HTList_delete(request->error_stack);
201: request->error_stack = NULL;
202: return;
203: }
204:
205:
206: /* HTErrorIgnore
207: **
2.12 frystyk 208: ** Turns on the `ignore' flag for the error with the current handle in
209: ** the error list. If the list is empty, nothing is done.
210: */
211: PUBLIC void HTErrorIgnore ARGS2(HTRequest *, request, int, handle)
212: {
213: BOOL found = NO;
214: HTList *cur;
215: HTErrorInfo *pres;
216: if (!request) {
2.22 ! frystyk 217: if (TRACE) fprintf(TDEST, "HTErrorIgnore Bad argument!\n");
2.12 frystyk 218: return;
219: }
220: cur = request->error_stack;
221: while ((pres = (HTErrorInfo *) HTList_nextObject(cur))) {
222: if (pres->handle == handle) {
223: pres->ignore = YES;
224: found = YES;
225: break;
226: }
227: }
228:
229: if (TRACE) {
230: if (found) {
2.22 ! frystyk 231: fprintf(TDEST, "Error Ignore Handle: %d\tCode: %3d\tMessage: `%s\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
2.12 frystyk 232: pres->handle,
233: error_info[pres->element].code,
234: error_info[pres->element].msg,
235: pres->severity,
236: pres->par ? (char *) pres->par : "Unspecified",
237: pres->where ? pres->where : "Unspecified");
238: } else {
2.22 ! frystyk 239: fprintf(TDEST, "Error Ignore Bad handle\n");
2.12 frystyk 240: }
241: }
242: return;
243: }
244:
245:
246: /* HTErrorIgnoreLast
247: **
2.1 frystyk 248: ** Turns on the `ignore' flag for the most recent error entered the
249: ** error list. If the list is empty, nothing is done.
250: */
2.12 frystyk 251: PUBLIC void HTErrorIgnoreLast ARGS1(HTRequest *, request)
2.1 frystyk 252: {
2.5 frystyk 253: HTList *cur;
2.1 frystyk 254: HTErrorInfo *pres;
255: if (!request) {
2.22 ! frystyk 256: if (TRACE) fprintf(TDEST, "HTErrorIgnore Bad argument!\n");
2.1 frystyk 257: return;
258: }
2.5 frystyk 259: cur = request->error_stack;
2.2 frystyk 260: if (cur && (pres = (HTErrorInfo *) HTList_nextObject(cur)) != NULL) {
261: if (TRACE)
2.22 ! frystyk 262: fprintf(TDEST, "Error Ignore Code: %3d\tMessage: `%s\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
2.2 frystyk 263: error_info[pres->element].code,
264: error_info[pres->element].msg,
265: pres->severity,
266: pres->par ? (char *) pres->par : "Unspecified",
267: pres->where ? pres->where : "Unspecified");
2.1 frystyk 268: pres->ignore = YES;
2.2 frystyk 269: }
2.1 frystyk 270: return;
2.17 frystyk 271: }
272:
273:
274: /* HTErrorSetPrefix
275: **
276: ** Sets the prefix for error URLs in the error message
277: */
278: PUBLIC void HTErrorSetPrefix ARGS1(char *, path)
279: {
280: if (path && *path)
281: StrAllocCopy(HTErrorPrefix, path);
282: }
283:
284:
285: /* HTErrorGetPrefix
286: **
287: ** Gets the prefix for error URLs in the error message
288: */
289: PUBLIC CONST char *HTErrorGetPrefix NOARGS
290: {
291: return HTErrorPrefix;
2.1 frystyk 292: }
293:
294:
295: /* HTErrorMsg
296: **
2.12 frystyk 297: ** Creates an error message on standard error containing the
298: ** error_stack messages.
2.1 frystyk 299: */
2.2 frystyk 300:
2.22 ! frystyk 301: /* *** LOOK IN HTErrMsg.c FOR ACTUAL IMPLEMENTATION OF THIS FUNCTION *** */
2.1 frystyk 302:
303: /* END OF MODULE */
304:
305:
306:
307:
308:
Webmaster