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

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

Webmaster