1 /*
2 
3 
4   					W3C Sample Code Library libwww Error Class
5 
6 
7 !
8   The Error Class
9 !
10 */
11 
12 /*
13 **	(c) COPYRIGHT MIT 1995.
14 **	Please first read the full copyright statement in the file COPYRIGH.
15 */
16 
17 /*
18 
19 The Error class provides an easy API for registering errors ocurring while
20 libwww serves a request. All errors are registered in an "error stack" in
21 the Request object which allows for nested errors.
22 The Error class is both natural language independent and application independent
23 in that it uses enumerations in order to refer to specific errors. It is
24 for the application to provide an error presentation module which interprets
25 the errors associated with a request. An eample of such an implementation
26 can be found in the HTDialog module.
27 
28 This module is implemented by HTError.c, and it is
29 a part of the  W3C Sample Code
30 Library.
31 */
32 
33 #ifndef HTERROR_H
34 #define HTERROR_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 typedef struct _HTError HTError;
41 
42 typedef enum _HTSeverity {
43     ERR_UNKNOWN		  = 0x0,
44     ERR_FATAL		  = 0x1,
45     ERR_NON_FATAL	  = 0x2,
46     ERR_WARN	 	  = 0x4,
47     ERR_INFO	 	  = 0x8
48 } HTSeverity;
49 
50 #include "HTReq.h"
51 
52 /*
53 .
54   The Error Message Object
55 .
56 
57 An error consists of a messsage code, a short, natural language specific
58 message, and a URI which can point to more information. This module also
59 provides a default set of error objects with English text.
60 Errors are registered together with a severity and you can also set the mode
61 for what class of error severities should be shown and which
62 should be ignored.
63 */
64 
65 typedef struct _HTErrorMessage {
66     int  	code;           	/* Error number */
67     char *	msg;          		/* Short explanation */
68     char *	url;			/* Explaning URL */
69 } HTErrorMessage;
70 
71 /*
72 (
73   Error Message Index
74 )
75 
76 Note: All non-HTTP error codes have (index number >
77 HTERR_HTTP_CODES), and they will not be shown in the error-message
78 generated.
79 
80 Error codes are registered in an array where the following enumerations serve
81 as an index. They must not be replaced! See the
82 HTDialog module for default initialization
83 of these messages.
84 */
85 
86 typedef enum _HTErrorElement {
87 	HTERR_CONTINUE = 0,					/* 100 */
88 	HTERR_SWITCHING,					/* 101 */
89 	HTERR_OK,						/* 200 */
90 	HTERR_CREATED,						/* 201 */
91 	HTERR_ACCEPTED,						/* 202 */
92 	HTERR_NON_AUTHORITATIVE,				/* 203 */
93 	HTERR_NO_CONTENT,					/* 204 */
94 	HTERR_RESET,						/* 205 */
95 	HTERR_PARTIAL,						/* 206 */
96 	HTERR_PARTIAL_OK,					/* 207 */
97 	HTERR_MULTIPLE,						/* 300 */
98 	HTERR_MOVED,						/* 301 */
99 	HTERR_FOUND,						/* 302 */
100 	HTERR_METHOD,						/* 303 */
101 	HTERR_NOT_MODIFIED,					/* 304 */
102 	HTERR_USE_PROXY,					/* 305 */
103 	HTERR_PROXY_REDIRECT,					/* 306 */
104 	HTERR_TEMP_REDIRECT,					/* 307 */
105 	HTERR_BAD_REQUEST,					/* 400 */
106 	HTERR_UNAUTHORIZED,					/* 401 */
107 	HTERR_PAYMENT_REQUIRED,					/* 402 */
108 	HTERR_FORBIDDEN,					/* 403 */
109 	HTERR_NOT_FOUND,					/* 404 */
110 	HTERR_NOT_ALLOWED,					/* 405 */
111 	HTERR_NONE_ACCEPTABLE,					/* 406 */
112 	HTERR_PROXY_UNAUTHORIZED,				/* 407 */
113 	HTERR_TIMEOUT,						/* 408 */
114 	HTERR_CONFLICT,						/* 409 */
115 	HTERR_GONE,						/* 410 */
116 	HTERR_LENGTH_REQUIRED,					/* 411 */
117 	HTERR_PRECON_FAILED,					/* 412 */
118 	HTERR_TOO_BIG,						/* 413 */
119 	HTERR_URI_TOO_BIG,					/* 414 */
120 	HTERR_UNSUPPORTED,					/* 415 */
121 	HTERR_BAD_RANGE,					/* 416 */
122 	HTERR_EXPECTATION_FAILED,				/* 417 */
123 	HTERR_REAUTH,				                /* 418 */
124 	HTERR_PROXY_REAUTH,				        /* 419 */
125 	HTERR_INTERNAL,						/* 500 */
126 	HTERR_NOT_IMPLEMENTED,					/* 501 */
127 	HTERR_BAD_GATE,						/* 502 */
128 	HTERR_DOWN,						/* 503 */
129 	HTERR_GATE_TIMEOUT,					/* 504 */
130 	HTERR_BAD_VERSION,					/* 505 */
131 	HTERR_NO_PARTIAL_UPDATE,				/* 506 */
132 
133 #ifdef HT_DAV
134 	/* WebDAV error codes */
135 	HTERR_UNPROCESSABLE,					/* 422 */
136 	HTERR_LOCKED,           				/* 423 */
137 	HTERR_FAILED_DEPENDENCY,				/* 424 */
138 	HTERR_INSUFFICIENT_STORAGE,				/* 507 */
139 #endif
140 
141 	/* Cache warnings */
142 	HTERR_STALE,						/* 10 */
143 	HTERR_REVALIDATION_FAILED,				/* 11 */
144 	HTERR_DISCONNECTED_CACHE,				/* 12 */
145 	HTERR_HEURISTIC_EXPIRATION,				/* 13 */
146 	HTERR_TRANSFORMED,					/* 14 */
147 	HTERR_CACHE,						/* 99 */
148 
149 	/* Put all non-HTTP status codes after this */
150 	HTERR_NO_REMOTE_HOST,
151 	HTERR_NO_HOST,
152 	HTERR_NO_FILE,
153 	HTERR_FTP_SERVER,
154 	HTERR_FTP_NO_RESPONSE,
155         HTERR_FTP_LOGIN_FAILURE,
156 	HTERR_TIME_OUT,
157 	HTERR_GOPHER_SERVER,
158 	HTERR_INTERRUPTED,
159 	HTERR_CON_INTR,
160 	HTERR_CSO_SERVER,
161 	HTERR_HTTP09,
162 	HTERR_BAD_REPLY,
163 	HTERR_UNKNOWN_AA,
164 	HTERR_NEWS_SERVER,
165 	HTERR_FILE_TO_FTP,
166 	HTERR_AUTO_REDIRECT,
167 	HTERR_MAX_REDIRECT,
168 	HTERR_EOF,
169 	HTERR_WAIS_OVERFLOW,
170 	HTERR_WAIS_MODULE,
171 	HTERR_WAIS_NO_CONNECT,
172 	HTERR_SYSTEM,
173 	HTERR_CLASS,
174 	HTERR_ACCESS,
175 	HTERR_LOGIN,
176         HTERR_CACHE_EXPIRED,
177         HTERR_NO_AUTO_RULES,
178         HTERR_NO_AUTO_PROXY,
179 	HTERR_ELEMENTS		            /* This MUST be the last element */
180 } HTErrorElement;
181 
182 /*
183 (
184   Default English Language Messages
185 )
186 
187 Default set of error messages arranged in an array into which the
188 index codes serve as index. See the
189 HTDialog module for default initialization
190 of these strings.
191 .
192   What Errors should be Ignored or Passed Through?
193 .
194 
195 This variable dictates which errors should be put out when generating the
196 message to the user. The first four enumerations make it possible to see
197 `everything as bad or worse than' this level, e.g. HT_ERR_SHOW_NON_FATAL
198 shows messages of type HT_ERR_SHOW_NON_FATAL and
199 HT_ERR_SHOW_FATAL.
200 
201 Note: The default value is made so that it only puts a message to
202 stderr if a `real' error has occurred. If a separate widget is available
203 for information and error messages then probably
204 HT_ERR_SHOW_DETAILED would be more appropriate.
205 */
206 
207 typedef enum _HTErrorShow {
208     HT_ERR_SHOW_FATAL     = 0x1,
209     HT_ERR_SHOW_NON_FATAL = 0x3,
210     HT_ERR_SHOW_WARNING   = 0x7,
211     HT_ERR_SHOW_INFO 	  = 0xF,
212     HT_ERR_SHOW_PARS	  = 0x10,
213     HT_ERR_SHOW_LOCATION  = 0x20,
214     HT_ERR_SHOW_IGNORE    = 0x40,
215     HT_ERR_SHOW_FIRST     = 0x80,
216     HT_ERR_SHOW_LINKS     = 0x100,
217     HT_ERR_SHOW_DEFAULT	  = 0x13,
218     HT_ERR_SHOW_DETAILED  = 0x1F,
219     HT_ERR_SHOW_DEBUG	  = 0x7F
220 } HTErrorShow;
221 
222 extern HTErrorShow HTError_show (void);
223 extern BOOL HTError_setShow (HTErrorShow mask);
224 
225 /*
226 .
227   Creation and Deletion Methods
228 .
229 (
230   Add an Error
231 )
232 
233 Add an error message to the error list. `par' and `where' might be set to
234 NULL. If par is a string, it is sufficient to let length be unspecified,
235 i.e., 0. If only a part of the string is wanted then specify a length inferior
236 to strlen((char *) par). The string is '\0' terminated automaticly. See also
237 HTError_addSystem for system errors. Returns YES if OK, else NO.
238 */
239 
240 extern BOOL HTError_add (HTList * 	list,
241 			 HTSeverity	severity,
242 			 BOOL		ignore,
243 			 int		element,
244 			 void *		par,
245 			 unsigned int	length,
246 			 char *		where);
247 
248 
249 /*
250 (
251   Add a System Error
252 )
253 
254 Add a system error message to the error list. syscall is the name of the
255 system call, e.g. "close". The message put to the list is that corresponds
256 to the error number passed. See also HTError_add. Returns YES if OK, else
257 NO.
258 */
259 
260 extern BOOL HTError_addSystem (HTList *		list,
261 			       HTSeverity 	severity,
262 			       int		errornumber,
263 			       BOOL		ignore,
264 			       char *		syscall);
265 
266 /*
267 (
268   Delete an Entire Error Stack
269 )
270 
271 Deletes all errors in a list.
272 */
273 
274 extern BOOL HTError_deleteAll (HTList * list);
275 
276 /*
277 (
278   Deletes the Last Edded Entry
279 )
280 
281 Deletes the last error entry added to the list. Return YES if OK, else NO
282 */
283 
284 extern BOOL HTError_deleteLast (HTList * list);
285 
286 /*
287 .
288   Object Methods
289 .
290 (
291   Show the Error Entry?
292 )
293 
294 Should we show this entry in the list or just continue to the next one?
295 */
296 
297 extern BOOL HTError_doShow (HTError * info);
298 
299 /*
300 (
301   Ignore last Added Error
302 )
303 
304 Turns on the `ignore' flag for the most recent error entered the error list.
305 Returns YES if OK else NO
306 */
307 
308 extern BOOL HTError_ignoreLast	(HTList * list);
309 extern BOOL HTError_setIgnore	(HTError * info);
310 
311 /*
312 (
313   Error Index Number
314 )
315 
316 Each error object is assigned an index number as defined by the
317 HTErrorElement above. The mapping from this index to an error
318 code and a message must be done by the application. The Library provides
319 a default implementation in the  HTDialog module,
320 but that can of course be changed depending on the application.
321 */
322 
323 extern int HTError_index		(HTError * info);
324 
325 /*
326 (
327   Error Severity
328 )
329 
330 This function returns the severity of the error object passed by the caller
331 */
332 extern HTSeverity HTError_severity	(HTError * info);
333 
334 /*
335 
336 You can ask whether a list of errors contains any error object with a severity
337 level which is higher than the one specifed.
338 */
339 extern BOOL HTError_hasSeverity 	(HTList * list, HTSeverity severity);
340 
341 /*
342 (
343   Parameters Asscotiated with Error
344 )
345 */
346 
347 extern void * HTError_parameter		(HTError * info, int * length);
348 
349 /*
350 (
351   Where did it happen?
352 )
353 */
354 
355 extern const char * HTError_location	(HTError * info);
356 
357 /*
358 */
359 
360 #ifdef __cplusplus
361 }
362 #endif
363 
364 #endif /* HTERROR_H */
365 
366 /*
367 
368 
369 
370   @(#) $Id$
371 
372 */
373