Annotation of libwww/Library/src/HTError.c, revision 2.12
2.1 frystyk 1: /* Error Report Module
2: ** ===================
3: **
4: ** This is the implementaion of an error message reporting system that
5: ** reports errors occured either in a stream module (structured streams
6: ** inclusive) or in a protocol module. A list of errors are put into the
7: ** request structure and freed together with this.
8: **
9: ** History:
10: ** 05 May 94 Written by Henrik Frystyk, frystyk@dxcern.cern.ch
11: */
12:
13: /* Implemention dependent include files */
14: #include "tcp.h"
15:
16: /* Library include files */
17: #include "HTUtils.h"
18: #include "HTAccess.h"
2.2 frystyk 19: #include "HTTCP.h"
2.1 frystyk 20: #include "HTError.h" /* Implemented here */
21:
22: /* Globals */
2.12 ! frystyk 23: PUBLIC unsigned int HTErrorShowMask = HT_ERR_SHOW_DEFAULT;
2.1 frystyk 24:
25: /* Type definitions and global variables etc. local to this module */
26:
27: /* All errors that are not strictly HTTP errors but originates from, e.g.,
28: the FTP protocol all have element numbers > HTERR_HTTP_CODES_END, i.e.,
2.8 frystyk 29: they should be placed after the blank line
30:
31: NOTE: codes marked `HTTP' should be future HTTP error codes.
32: */
2.4 frystyk 33: PUBLIC HTErrorMsgInfo error_info[HTERR_ELEMENTS] = {
2.1 frystyk 34: { 200, "OK", "ok.multi" },
35: { 201, "Created", "created.multi" },
36: { 202, "Accepted", "accepted.multi" },
37: { 203, "Partial Information", "partial.multi" },
2.8 frystyk 38: { 204, "No Response", "no_response.multi" },
2.1 frystyk 39: { 301, "Moved", "moved.multi" },
40: { 302, "Found", "found.multi" },
41: { 303, "Method", "method.multi" },
2.8 frystyk 42: { 304, "Not Modified Since", "not_modified.multi" },
43: { 400, "Invalid Request", "bad_request.multi" },
44: { 401, "Unauthorized Access Denied","unauthorized.multi" },
2.1 frystyk 45: { 402, "Payment Required", "payment.multi" },
2.8 frystyk 46: { 403, "Access forbidden by rule", "forbidden.multi" },
47: { 404, "No Match Found for", "not_found.multi" },
48: { 500, "Can't Access Document", "internal.multi" },
49: { 501, "Command not Implemented", "not_implemented.multi" },
2.1 frystyk 50: { 0, "-------------------------", "-----------------------" },
51: { 0, "Can't locate remote host", "locate_host.multi" },
52: { 0, "FTP-server replies", "ftp.multi" },
53: { 0, "FTP-server doesn't reply", "no_server.multi" },
2.2 frystyk 54: { 0, "Server timed out", "time_out.multi" },
55: { 0, "Gopher-server replies", "gopher.multi" },
2.8 frystyk 56: { 0, "Data transfer interrupted", "interrupt.multi" },
2.2 frystyk 57: { 0, "CSO-server replies", "cso.multi" },
2.9 frystyk 58: { 0, "Bad or Incomplete Response","bad_reply.multi" }, /* HTTP */
2.8 frystyk 59: { 0, "News-server replies", "news.multi" },
2.12 ! frystyk 60: { 0, "Trying `ftp://' instead of `file://'. ANY OLD URL STILL USING WRONG ACCESS METHOD WILL BE OBSOLETE IN THE NEXT MAJOR RELEASE!","ftpfile.multi" },
2.8 frystyk 61: { 0, "System call `%s' failed: ", "system.multi" }
2.1 frystyk 62: };
63:
64: /* ------------------------------------------------------------------------- */
65:
66: /* HTErrorAdd
67: **
68: ** Add an error message to the error list in HTRequest. `par' and `where'
2.2 frystyk 69: ** might be set to NULL. If par is a string, it is sufficient to let
2.8 frystyk 70: ** par_length be unspecified, i.e., 0. If only a part of the string is
71: ** wanted then specify a par_length inferior to strlen((char *) par).
72: ** The string is '\0' terminated automaticly.
2.2 frystyk 73: **
74: ** NOTE: See also HTErrorSysAdd for system errors
2.4 frystyk 75: **
76: ** Returns always < 0
2.1 frystyk 77: */
2.4 frystyk 78: PUBLIC int HTErrorAdd ARGS7(HTRequest *, request,
79: HTErrSeverity, severity,
80: BOOL, ignore,
81: int, element,
82: void *, par,
83: unsigned int, par_length,
84: char *, where)
2.1 frystyk 85: {
86: HTErrorInfo *newError;
87: if (!request) {
88: if (TRACE) fprintf(stderr, "HTErrorAdd.. Bad argument!\n");
2.4 frystyk 89: return -1;
2.1 frystyk 90: }
91: if ((newError = (HTErrorInfo *) calloc(1, sizeof(HTErrorInfo))) == NULL)
92: outofmem(__FILE__, "HTErrorAdd");
2.2 frystyk 93: newError->element = element;
94: newError->severity = severity;
2.1 frystyk 95: newError->ignore = ignore;
2.2 frystyk 96: if (par) {
97: if (!par_length)
98: par_length = (int) strlen((char *) par);
2.1 frystyk 99: if ((newError->par = malloc(par_length+1)) == NULL)
2.10 luotonen 100: outofmem(__FILE__, "HTErrorError");
2.1 frystyk 101: memcpy(newError->par, par, par_length);
102: *(((char *) newError->par)+par_length) = '\0';
103: newError->par_length = par_length;
104: }
105: newError->where = where;
2.12 ! frystyk 106:
! 107: /* Add to the stack in the request structure */
! 108: if (!request->error_stack)
! 109: request->error_stack = HTList_new();
! 110: else { /* Get last object in order to find a handle */
! 111: HTList *cur = request->error_stack;
! 112: HTErrorInfo *pres = (HTErrorInfo *) HTList_nextObject(cur);
! 113: if (pres != NULL)
! 114: newError->handle = pres->handle+1;
! 115: }
2.1 frystyk 116: if (TRACE) {
2.12 ! frystyk 117: fprintf(stderr, "Message..... Handle: %d\tCode: %3d\tMessage: `%s\'\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
! 118: newError->handle,
2.1 frystyk 119: error_info[newError->element].code,
120: error_info[newError->element].msg,
121: newError->severity,
122: newError->par ? (char *) newError->par : "Unspecified",
123: newError->where ? newError->where : "Unspecified");
124: }
125: HTList_addObject(request->error_stack, (void *) newError);
2.4 frystyk 126: return (-element);
2.1 frystyk 127: }
128:
129:
2.2 frystyk 130: /* HTErrorSysAdd
131: **
132: ** Add a system error message to the error list in HTRequest. syscall
133: ** is the name of the system call, e.g. "close". The message put to the
134: ** list is that corresponds to the errno. This function also replaces
135: ** HTInetStatus, which is called from within.
136: **
137: ** See also HTErrorAdd.
2.4 frystyk 138: **
139: ** Returns always < 0
2.2 frystyk 140: */
2.4 frystyk 141: PUBLIC int HTErrorSysAdd ARGS4(HTRequest *, request,
142: HTErrSeverity, severity,
143: BOOL, ignore,
144: char *, syscall)
2.2 frystyk 145:
146: {
147: if (!request) {
148: if (TRACE) fprintf(stderr, "HTErrorSys.. Bad argument!\n");
2.4 frystyk 149: return -1;
2.2 frystyk 150: }
151: if (syscall) {
152: HTInetStatus(syscall);
153: } else
154: HTInetStatus("Unspecified System Call");
155: {
2.7 luotonen 156: char temp[100];
2.2 frystyk 157: char *errmsg = NULL;
2.7 luotonen 158: sprintf(temp, error_info[HTERR_SYSTEM].msg, syscall);
2.6 frystyk 159: StrAllocCopy(errmsg, temp);
160: StrAllocCat(errmsg, HTErrnoString());
2.12 ! frystyk 161: HTErrorAdd(request, severity, ignore, HTERR_SYSTEM, (void *) errmsg,
! 162: (int) strlen(errmsg), syscall);
! 163: free(errmsg);
2.2 frystyk 164: }
2.4 frystyk 165: return (-HTERR_SYSTEM);
2.2 frystyk 166: }
167:
168:
2.1 frystyk 169: /* HTErrorFree
170: **
171: ** Free the whole error stack from the HTRequest structure.
172: */
173: PUBLIC void HTErrorFree ARGS1(HTRequest *, request)
174: {
175: HTList *cur = request->error_stack;
176: HTErrorInfo *pres;
177: if (!request || !request->error_stack)
178: return;
179: while ((pres = (HTErrorInfo *) HTList_nextObject(cur))) {
180: FREE(pres->par);
181: free(pres);
182: }
183: HTList_delete(request->error_stack);
184: request->error_stack = NULL;
185: return;
186: }
187:
188:
189: /* HTErrorIgnore
190: **
2.12 ! frystyk 191: ** Turns on the `ignore' flag for the error with the current handle in
! 192: ** the error list. If the list is empty, nothing is done.
! 193: */
! 194: PUBLIC void HTErrorIgnore ARGS2(HTRequest *, request, int, handle)
! 195: {
! 196: BOOL found = NO;
! 197: HTList *cur;
! 198: HTErrorInfo *pres;
! 199: if (!request) {
! 200: if (TRACE) fprintf(stderr, "HTErrorIgnore Bad argument!\n");
! 201: return;
! 202: }
! 203: cur = request->error_stack;
! 204: while ((pres = (HTErrorInfo *) HTList_nextObject(cur))) {
! 205: if (pres->handle == handle) {
! 206: pres->ignore = YES;
! 207: found = YES;
! 208: break;
! 209: }
! 210: }
! 211:
! 212: if (TRACE) {
! 213: if (found) {
! 214: fprintf(stderr, "Error Ignore Handle: %d\tCode: %3d\tMessage: `%s\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
! 215: pres->handle,
! 216: error_info[pres->element].code,
! 217: error_info[pres->element].msg,
! 218: pres->severity,
! 219: pres->par ? (char *) pres->par : "Unspecified",
! 220: pres->where ? pres->where : "Unspecified");
! 221: } else {
! 222: fprintf(stderr, "Error Ignore Bad handle\n");
! 223: }
! 224: }
! 225: return;
! 226: }
! 227:
! 228:
! 229: /* HTErrorIgnoreLast
! 230: **
2.1 frystyk 231: ** Turns on the `ignore' flag for the most recent error entered the
232: ** error list. If the list is empty, nothing is done.
233: */
2.12 ! frystyk 234: PUBLIC void HTErrorIgnoreLast ARGS1(HTRequest *, request)
2.1 frystyk 235: {
2.5 frystyk 236: HTList *cur;
2.1 frystyk 237: HTErrorInfo *pres;
238: if (!request) {
239: if (TRACE) fprintf(stderr, "HTErrorIgnore Bad argument!\n");
240: return;
241: }
2.5 frystyk 242: cur = request->error_stack;
2.2 frystyk 243: if (cur && (pres = (HTErrorInfo *) HTList_nextObject(cur)) != NULL) {
244: if (TRACE)
245: fprintf(stderr, "Error Ignore Code: %3d\tMessage: `%s\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
246: error_info[pres->element].code,
247: error_info[pres->element].msg,
248: pres->severity,
249: pres->par ? (char *) pres->par : "Unspecified",
250: pres->where ? pres->where : "Unspecified");
2.1 frystyk 251: pres->ignore = YES;
2.2 frystyk 252: }
2.1 frystyk 253: return;
254: }
255:
256:
257: /* HTErrorMsg
258: **
2.12 ! frystyk 259: ** Creates an error message on standard error containing the
! 260: ** error_stack messages.
2.1 frystyk 261: */
2.2 frystyk 262:
2.4 frystyk 263: /* *** LOOK IN HTML.C FOR ACTUAL IMPLEMENTATION OF THIS FUNCTION *** */
2.1 frystyk 264:
265: /* END OF MODULE */
266:
267:
268:
269:
270:
Webmaster