Annotation of libwww/Library/src/HTError.c, revision 2.33
2.20 frystyk 1: /* HTError.c
2: ** ERROR REPORT MODULE
3: **
2.24 frystyk 4: ** (c) COPYRIGHT MIT 1995.
2.20 frystyk 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
2.31 frystyk 10: ** a list which can be bound to a request object or a stream
2.1 frystyk 11: **
12: ** History:
2.26 frystyk 13: ** 05 May 94 Written by Henrik Frystyk, frystyk@w3.org
2.31 frystyk 14: ** Nov 95 Made list as basic data structure
2.1 frystyk 15: */
16:
17: /* Library include files */
2.22 frystyk 18: #include "tcp.h"
19: #include "HTUtils.h"
20: #include "HTString.h"
2.17 frystyk 21: #include "HTTCP.h"
2.31 frystyk 22: #include "HTList.h"
2.1 frystyk 23: #include "HTError.h" /* Implemented here */
24:
2.31 frystyk 25: struct _HTError {
26: HTErrorElement element; /* Index number into HTError */
27: HTSeverity severity; /* A la VMS */
28: BOOL ignore; /* YES if msg should not go to user */
29: void * par; /* Explanation, e.g. filename */
30: int length; /* For copying by generic routine */
31: char * where; /* Which function */
32: };
2.1 frystyk 33:
2.33 ! frystyk 34: PRIVATE unsigned int HTShowMask = HT_ERR_SHOW_DEFAULT;
2.1 frystyk 35:
36: /* ------------------------------------------------------------------------- */
37:
2.31 frystyk 38: /* HTError_add
39: ** -----------
40: ** Add an error message to the error list. `par' and `where'
2.2 frystyk 41: ** might be set to NULL. If par is a string, it is sufficient to let
2.31 frystyk 42: ** length be unspecified, i.e., 0. If only a part of the string is
43: ** wanted then specify a length inferior to strlen((char *) par).
2.8 frystyk 44: ** The string is '\0' terminated automaticly.
2.31 frystyk 45: ** NOTE: See also HTError_addSystem for system errors
46: ** Return YES if OK, else NO
2.1 frystyk 47: */
2.31 frystyk 48: PUBLIC BOOL HTError_add (HTList * list,
49: HTSeverity severity,
50: BOOL ignore,
51: int element,
52: void * par,
53: unsigned int length,
54: char * where)
55: {
56: HTError *newError;
57: if (!list) return NO;
58: if ((newError = (HTError *) calloc(1, sizeof(HTError))) == NULL)
59: outofmem(__FILE__, "HTError_add");
2.18 frystyk 60: newError->element = (HTErrorElement) element;
2.2 frystyk 61: newError->severity = severity;
2.1 frystyk 62: newError->ignore = ignore;
2.2 frystyk 63: if (par) {
2.31 frystyk 64: if (!length) length = (int) strlen((char *) par);
65: if ((newError->par = malloc(length+1)) == NULL)
2.10 luotonen 66: outofmem(__FILE__, "HTErrorError");
2.31 frystyk 67: memcpy(newError->par, par, length);
68: *(((char *) newError->par)+length) = '\0';
69: newError->length = length;
2.1 frystyk 70: }
71: newError->where = where;
2.29 frystyk 72: if (WWWTRACE) {
2.33 ! frystyk 73: TTYPrint(TDEST, "Error Add... number: %3d\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
! 74: element,
2.1 frystyk 75: newError->severity,
76: newError->par ? (char *) newError->par : "Unspecified",
77: newError->where ? newError->where : "Unspecified");
78: }
2.31 frystyk 79: return HTList_addObject(list, (void *) newError);
2.1 frystyk 80: }
81:
82:
2.31 frystyk 83: /* HTError_addSystem
84: ** -----------------
85: ** Add a system error message to the error list. syscall
2.2 frystyk 86: ** is the name of the system call, e.g. "close". The message put to the
2.22 frystyk 87: ** list is that corresponds to the error number passed.
2.31 frystyk 88: ** Returns YES if OK, else NO
89: ** See also HTError_add.
2.2 frystyk 90: */
2.31 frystyk 91: PUBLIC BOOL HTError_addSystem (HTList * list,
92: HTSeverity severity,
93: int errornumber,
94: BOOL ignore,
95: char * syscall)
96: {
97: BOOL status = NO;
98: if (list && syscall) {
2.2 frystyk 99: char *errmsg = NULL;
2.31 frystyk 100: StrAllocCopy(errmsg, syscall);
101: StrAllocCat(errmsg, ": ");
2.22 frystyk 102: StrAllocCat(errmsg, HTErrnoString(errornumber));
2.31 frystyk 103: status = HTError_add(list, severity, ignore, HTERR_SYSTEM,
104: errmsg, (int) strlen(errmsg), syscall);
2.12 frystyk 105: free(errmsg);
2.2 frystyk 106: }
2.31 frystyk 107: return status;
2.2 frystyk 108: }
109:
2.31 frystyk 110: /* HTError_deleteAll
111: ** -----------------
112: ** Remove all errors from the list
2.1 frystyk 113: */
2.31 frystyk 114: PUBLIC BOOL HTError_deleteAll (HTList * list)
2.1 frystyk 115: {
2.31 frystyk 116: if (list) {
117: HTList *cur = list;
118: HTError *pres;
119: while ((pres = (HTError *) HTList_nextObject(cur))) {
120: FREE(pres->par);
121: free(pres);
122: }
123: HTList_delete(list);
124: return YES;
2.1 frystyk 125: }
2.31 frystyk 126: return NO;
2.1 frystyk 127: }
128:
2.31 frystyk 129: /* HTError_deleteLast
130: ** ------------------
131: ** Deletes the last error entry added to the list
132: ** Return YES if OK, else NO
2.12 frystyk 133: */
2.31 frystyk 134: PUBLIC BOOL HTError_deleteLast (HTList * list)
2.12 frystyk 135: {
2.31 frystyk 136: if (list) {
137: HTError *old = HTList_removeLastObject(list);
138: if (old) {
139: if (WWWTRACE) TTYPrint(TDEST, "Error.Delete %p\n", old);
140: FREE(old->par);
141: free(old);
142: return YES;
2.12 frystyk 143: }
144: }
2.31 frystyk 145: return NO;
146: }
2.12 frystyk 147:
2.31 frystyk 148: /* HTError_ignoreLast
149: ** ------------------
150: ** Turns on the `ignore' flag for the most recent error entered the
151: ** error list. Returns YES if OK else NO
152: */
153: PUBLIC BOOL HTError_ignoreLast (HTList * list)
154: {
155: if (list) {
156: HTError *last = HTList_lastObject(list);
157: if (last) {
158: if (WWWTRACE) TTYPrint(TDEST, "Error.Ignore %p\n", last);
159: last->ignore = YES;
160: return YES;
2.12 frystyk 161: }
162: }
2.31 frystyk 163: return NO;
2.12 frystyk 164: }
165:
2.31 frystyk 166: /* HTError_setIgnore
167: ** -----------------
2.1 frystyk 168: */
2.31 frystyk 169: PUBLIC BOOL HTError_setIgnore (HTError * info)
2.1 frystyk 170: {
2.31 frystyk 171: if (info) {
172: info->ignore = YES;
173: return YES;
2.1 frystyk 174: }
2.31 frystyk 175: return NO;
2.17 frystyk 176: }
177:
2.31 frystyk 178: /*
179: ** Get show preferences
2.17 frystyk 180: */
2.31 frystyk 181: PUBLIC HTErrorShow HTError_show (void)
2.17 frystyk 182: {
2.31 frystyk 183: return HTShowMask;
2.17 frystyk 184: }
185:
2.31 frystyk 186: PUBLIC BOOL HTError_setShow (HTErrorShow mask)
187: {
188: HTShowMask = mask;
189: return YES;
190: }
2.17 frystyk 191:
2.31 frystyk 192: /*
193: ** Should we show this error entry?
2.17 frystyk 194: */
2.31 frystyk 195: PUBLIC BOOL HTError_doShow (HTError *info)
2.17 frystyk 196: {
2.31 frystyk 197: return (info && ((HTShowMask & info->severity) &&
198: (!info->ignore || HTShowMask & HT_ERR_SHOW_IGNORE)));
2.1 frystyk 199: }
200:
2.31 frystyk 201: /*
202: ** Various Fields in the HTError structure
2.1 frystyk 203: */
2.31 frystyk 204: PUBLIC HTSeverity HTError_severity (HTError *info)
205: {
206: return info ? info->severity : 0;
207: }
2.2 frystyk 208:
2.33 ! frystyk 209: PUBLIC int HTError_index (HTError * info)
2.31 frystyk 210: {
2.33 ! frystyk 211: return info ? info->element : -1;
2.31 frystyk 212: }
2.1 frystyk 213:
2.31 frystyk 214: PUBLIC void * HTError_parameter (HTError * info, int * length)
215: {
216: if (info) {
217: *length = info->length;
218: return info->par;
219: }
220: return NULL;
221: }
2.1 frystyk 222:
2.31 frystyk 223: PUBLIC CONST char * HTError_location (HTError * info)
224: {
225: return info ? info->where : NULL;
226: }
Webmaster