Annotation of libwww/Library/src/HTError.html, revision 2.19

2.1       frystyk     1: <HTML>
                      2: <HEAD>
                      3: <TITLE>Error message module for libwww</TITLE>
                      4: <NEXTID N="z1">
                      5: </HEAD>
                      6: <BODY>
2.18      frystyk     7: 
2.9       frystyk     8: <H1>Reporting Errors and Messages to the Client</H1>
2.1       frystyk     9: 
2.18      frystyk    10: <PRE>
                     11: /*
                     12: **     (c) COPYRIGHT CERN 1994.
                     13: **     Please first read the full copyright statement in the file COPYRIGH.
                     14: */
                     15: </PRE>
                     16: 
2.15      frystyk    17: This module maintaines a list of error messages that might occur
                     18: during load of a requested URL. The error list is put out to standard
                     19: output by a simple function that easily can be overwritten by a smart
2.18      frystyk    20: server or client.  <P>
2.15      frystyk    21: 
                     22: <NOTE><B>Note: </B></NOTE> At the moment, <A
                     23: HREF="HTErrorMsg.c">HTErrorMsg()</A> is called, if the flag
                     24: HTRequest-&gt;error_block is set to YES, then a stream has been put up
                     25: or taken down in the library and therefore it is <B>VERY</B> unsafe to
2.18      frystyk    26: put anything more to the stream. <P>
                     27: 
                     28: This module is implemented by <A HREF="HTError.c">HTError.c</A>, and
                     29: it is a part of the <A
                     30: HREF="http://info.cern.ch/hypertext/WWW/Library/User/Guide/Guide.html">
                     31: Library of Common Code</A>.
2.4       frystyk    32: 
2.1       frystyk    33: <PRE>
                     34: #ifndef HTERROR_H
                     35: #define HTERROR_H
2.19    ! roeber     36: #include "sysdep.h"
2.15      frystyk    37: #include "HTAccess.h"
2.1       frystyk    38: </PRE>
                     39: 
2.3       frystyk    40: <H2>Data Structures</H2>
2.1       frystyk    41: 
2.15      frystyk    42: The basic data structure is HTErrorInfo, but in addition the following
                     43: types are used:
2.1       frystyk    44: 
2.3       frystyk    45: <H3>Error Numbers</H3>
2.1       frystyk    46: 
2.15      frystyk    47: <NOTE><B>Note: </B></NOTE> All non-HTTP error codes have index numbers
                     48: &gt; HTERR_HTTP_CODES, and they will not be shown in the error-message
                     49: generated.
                     50: 
2.1       frystyk    51: <PRE>
                     52: typedef enum _HTErrorElement {
                     53:        HTERR_OK = 0,                                           /* 200 */
                     54:        HTERR_CREATED,                                          /* 201 */
                     55:        HTERR_ACCEPTED,                                         /* 202 */
                     56:        HTERR_PARTIAL,                                          /* 203 */
                     57:        HTERR_NO_RESPONSE,                                      /* 204 */
                     58:        HTERR_MOVED,                                            /* 301 */
                     59:        HTERR_FOUND,                                            /* 302 */
                     60:        HTERR_METHOD,                                           /* 303 */
                     61:        HTERR_NOT_MODIFIED,                                     /* 304 */
                     62:        HTERR_BAD_REQUEST,                                      /* 400 */
                     63:        HTERR_UNAUTHORIZED,                                     /* 401 */
                     64:        HTERR_PAYMENT_REQUIRED,                                 /* 402 */
                     65:        HTERR_FORBIDDEN,                                        /* 403 */
                     66:        HTERR_NOT_FOUND,                                        /* 404 */
                     67:        HTERR_INTERNAL,                                         /* 500 */
                     68:        HTERR_NOT_IMPLEMENTED,                                  /* 501 */
                     69:        HTERR_HTTP_CODES_END,    /* Put all non-HTTP status codes after this */
                     70:        HTERR_NO_REMOTE_HOST,
2.13      frystyk    71:        HTERR_NO_HOST,
2.1       frystyk    72:        HTERR_FTP_SERVER,
                     73:        HTERR_FTP_NO_RESPONSE,
                     74:        HTERR_TIME_OUT,
2.2       frystyk    75:        HTERR_GOPHER_SERVER,
                     76:        HTERR_INTERRUPTED,
2.13      frystyk    77:        HTERR_CON_INTR,
2.2       frystyk    78:        HTERR_CSO_SERVER,
2.16      frystyk    79:        HTERR_HTTP09,                                           /* HTTP */
2.5       frystyk    80:        HTERR_BAD_REPLY,                                        /* HTTP */
2.16      frystyk    81:        HTERR_UNKNOWN_AA,
2.5       frystyk    82:        HTERR_NEWS_SERVER,
2.7       frystyk    83:        HTERR_FILE_TO_FTP,
2.8       frystyk    84:        HTERR_MAX_REDIRECT,
2.16      frystyk    85:        HTERR_EOF,
2.14      frystyk    86:        HTERR_WAIS_OVERFLOW,
                     87:        HTERR_WAIS_MODULE,
2.12      frystyk    88:        HTERR_WAIS_NO_CONNECT,
2.2       frystyk    89:        HTERR_SYSTEM,
2.1       frystyk    90:        HTERR_ELEMENTS                      /* This MUST be the last element */
                     91: } HTErrorElement;
2.19    ! roeber     92: 
        !            93: #ifdef ERR_WARNING
        !            94: #undef ERR_WARNING
        !            95: #endif
2.3       frystyk    96: 
                     97: typedef enum _HTErrSeverity {
                     98:     ERR_FATAL            = 0x1,
2.7       frystyk    99:     ERR_NON_FATAL        = 0x2,
                    100:     ERR_WARNING          = 0x4,
                    101:     ERR_INFO             = 0x8
2.3       frystyk   102: } HTErrSeverity;
                    103: 
                    104: typedef struct _HTErrorInfo {
2.7       frystyk   105:     int                        handle;         /* Unique number in this stack */
2.3       frystyk   106:     HTErrorElement     element;        /* Index number into HTErrorMsgInfo */
                    107:     HTErrSeverity      severity;       /* A la VMS */
                    108:     BOOL                       ignore;         /* YES if msg should not go to user */
                    109:     void *             par;            /* Explanation, e.g. filename  */
                    110:     unsigned int       par_length;     /* For copying by generic routine */
                    111:     char *             where;          /* Which function */
                    112: } HTErrorInfo;
2.1       frystyk   113: </PRE>
                    114: 
2.3       frystyk   115: <H2>Controling Globals</H2>
                    116: 
2.15      frystyk   117: This variable dictates which errors should be put out when generating
                    118: the message to the user. The first four enumerations make it possible
                    119: to see `everything as bad or worse than' this level, e.g.
                    120: HT_ERR_SHOW_NON_FATAL shows messages of type HT_ERR_SHOW_NON_FATAL and
                    121: HT_ERR_SHOW_FATAL. <P>
                    122: 
                    123: <B>Note:</B> The default value is made so that it only puts a message
                    124: to <EM>stderr</EM> if a `real' error has occurred. If a separate
                    125: widget is available for information and error messages then probably
                    126: HT_ERR_SHOW_DETAILED would be more appropriate.
2.3       frystyk   127: 
                    128: <PRE>
                    129: typedef enum _HTErrorShow {
                    130:     HT_ERR_SHOW_FATAL     = 0x1,
                    131:     HT_ERR_SHOW_NON_FATAL = 0x3,
                    132:     HT_ERR_SHOW_WARNING   = 0x7,
2.6       frystyk   133:     HT_ERR_SHOW_INFO     = 0xF,
                    134:     HT_ERR_SHOW_PARS     = 0x10,
                    135:     HT_ERR_SHOW_LOCATION  = 0x20,
                    136:     HT_ERR_SHOW_IGNORE    = 0x40,
                    137:     HT_ERR_SHOW_FIRST     = 0x80,
2.15      frystyk   138:     HT_ERR_SHOW_LINKS     = 0x100,
2.7       frystyk   139:     HT_ERR_SHOW_DEFAULT          = 0x13,
                    140:     HT_ERR_SHOW_DETAILED  = 0x1F,
2.10      frystyk   141:     HT_ERR_SHOW_DEBUG    = 0x7F
2.3       frystyk   142: } HTErrorShow;
                    143: 
                    144: extern unsigned int HTErrorShowMask;
                    145: </PRE>
2.1       frystyk   146: 
2.15      frystyk   147: This is the table containing the actual error-messages and links for
                    148: more information:
2.1       frystyk   149: 
                    150: <PRE>
2.3       frystyk   151: typedef struct _HTErrorMsgInfo {
                    152:     int        code;                   /* Error number */
                    153:     char *     msg;                    /* Short explanation */
                    154:     char *     url;                    /* Explaning URL */
                    155: } HTErrorMsgInfo;
                    156: 
                    157: extern HTErrorMsgInfo error_info[];
2.1       frystyk   158: </PRE>
                    159: 
2.3       frystyk   160: <H2>Public Error Functions</H2>
                    161: 
2.1       frystyk   162: <H3>Add an Error Message</H3>
                    163: 
                    164: This function adds an error message to the error_stack list in the HTRequest
2.3       frystyk   165: structure. It always returns a negative value.
2.1       frystyk   166: <PRE>
2.3       frystyk   167: extern int HTErrorAdd PARAMS(( HTRequest *     request,
2.1       frystyk   168:                                HTErrSeverity   severity,
                    169:                                BOOL            ignore,
                    170:                                int             element,
                    171:                                void *          par,
                    172:                                unsigned int    par_length,
                    173:                                char *          where));
2.2       frystyk   174: </PRE>
                    175: 
                    176: <H3>Add a System Error Message</H3>
                    177: 
2.15      frystyk   178: This function adds an error from a system call that initializes errno
                    179: or equivalent and adds it to the error_stack list in the HTRequest
                    180: structure. It always returns a negative value.
                    181: 
2.2       frystyk   182: <PRE>
2.3       frystyk   183: extern int HTErrorSysAdd PARAMS(( HTRequest *  request,
2.2       frystyk   184:                                  HTErrSeverity severity,
                    185:                                  BOOL          ignore,
                    186:                                  char *        syscall));
2.1       frystyk   187: </PRE>
                    188: 
                    189: <H3>Ignoring an Error Message</H3>
                    190: 
2.15      frystyk   191: If an error message is not to be send to the user, e.g., output to the
                    192: stream, then the ignore flag must be turn on. Theese functions turns
                    193: it on for the latest error appended to the list or an arbitrary error
                    194: refered to by its handle.
                    195: 
2.1       frystyk   196: <PRE>
2.7       frystyk   197: extern void HTErrorIgnore PARAMS((HTRequest * request, int handle));
                    198: extern void HTErrorIgnoreLast PARAMS((HTRequest * request));
2.1       frystyk   199: </PRE>
                    200: 
2.15      frystyk   201: <H3>Handling Prefix for Links in Error Message</H3>
                    202: 
                    203: Two functions handle the URL prefix of the links inside the error
                    204: message. They are quite obvious:
                    205: 
                    206: <PRE>
2.17      frystyk   207: extern void HTErrorSetPrefix PARAMS((char *path));
                    208: extern CONST char *HTErrorGetPrefix NOPARAMS;
2.15      frystyk   209: </PRE>
                    210: 
2.7       frystyk   211: <H3>Generating an Error Message (default to standard error)</H3>
2.3       frystyk   212: 
2.8       frystyk   213: This function outputs the content of the error_stack to standard output 
                    214: (used in Line Mode Browser), but smart clients and servers might overwrite
                    215: this function so that the error messages can be handled to the user in a nice 
                    216: way. That is the reason for putting the actual implementation in HTErrorMsg.c,
                    217: that can be overwritten by clients and servers apart from Line Mode Browser.<P>
2.3       frystyk   218: 
2.4       frystyk   219: <NOTE><B>Note: </B></NOTE>
2.1       frystyk   220: 
2.8       frystyk   221: If a stream <EM>has</EM> been put up (and maybe taken down again) inside the 
                    222: Library, then request-&gt;error_block has been set to YES. This indicates that
                    223: it is NOT possible any more to use the stream as output for the message.
2.1       frystyk   224: <PRE>
2.17      frystyk   225: extern void HTErrorMsg    PARAMS((HTRequest * request));
2.1       frystyk   226: </PRE>
                    227: 
                    228: <H3>Freeing an Error List</H3>
                    229: 
2.8       frystyk   230: This is normally done when the HTRequest structure is freed but it might be 
                    231: done at any other time in order to ignore a whole series of errors.
2.1       frystyk   232: <PRE>
2.17      frystyk   233: extern void HTErrorFree   PARAMS((HTRequest * request));
2.1       frystyk   234: </PRE>
                    235: 
                    236: <PRE>
                    237: #endif
                    238: </PRE>
                    239: end
                    240: </BODY>
                    241: </HTML>
                    242: 
                    243: 

Webmaster