Annotation of libwww/Library/src/HTError.c, revision 2.11

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.2       frystyk    23: PUBLIC unsigned int HTErrorShowMask = HT_ERR_SHOW_WARNING+HT_ERR_SHOW_PARS;
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" },
                     60:     { 0,   "System call `%s' failed: ",        "system.multi" }
2.1       frystyk    61: };
                     62: 
                     63: /* ------------------------------------------------------------------------- */
                     64: 
                     65: /*                                                             HTErrorAdd
                     66: **
                     67: **     Add an error message to the error list in HTRequest. `par' and `where'
2.2       frystyk    68: **     might be set to NULL. If par is a string, it is sufficient to let
2.8       frystyk    69: **     par_length be unspecified, i.e., 0. If only a part of the string is
                     70: **     wanted then specify a par_length inferior to strlen((char *) par).
                     71: **     The string is '\0' terminated automaticly.
2.2       frystyk    72: **
                     73: **     NOTE: See also HTErrorSysAdd for system errors
2.4       frystyk    74: **
                     75: **     Returns always < 0
2.1       frystyk    76: */
2.4       frystyk    77: PUBLIC int HTErrorAdd ARGS7(HTRequest *,       request,
                     78:                            HTErrSeverity,      severity,
                     79:                            BOOL,               ignore,
                     80:                            int,                element,
                     81:                            void *,             par,
                     82:                            unsigned int,       par_length,
                     83:                            char *,             where)
2.1       frystyk    84: {
                     85:     HTErrorInfo *newError;
                     86:     if (!request) {
                     87:        if (TRACE) fprintf(stderr, "HTErrorAdd.. Bad argument!\n");
2.4       frystyk    88:        return -1;
2.1       frystyk    89:     }
                     90:     if ((newError = (HTErrorInfo *) calloc(1, sizeof(HTErrorInfo))) == NULL)
                     91:        outofmem(__FILE__, "HTErrorAdd");
2.2       frystyk    92:     newError->element = element;
                     93:     newError->severity = severity;
2.1       frystyk    94:     newError->ignore = ignore;
2.2       frystyk    95:     if (par) {
                     96:        if (!par_length)
                     97:            par_length = (int) strlen((char *) par);
2.1       frystyk    98:        if ((newError->par = malloc(par_length+1)) == NULL)
2.10      luotonen   99:            outofmem(__FILE__, "HTErrorError");
2.1       frystyk   100:        memcpy(newError->par, par, par_length);
                    101:        *(((char *) newError->par)+par_length) = '\0';
                    102:        newError->par_length = par_length;
                    103:     }
                    104:     newError->where = where;
                    105:     if (TRACE) {
2.11    ! frystyk   106:        fprintf(stderr, "Message..... Code: %3d\tMessage: `%s\'\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
2.1       frystyk   107:                error_info[newError->element].code,
                    108:                error_info[newError->element].msg,
                    109:                newError->severity,
                    110:                newError->par ? (char *) newError->par : "Unspecified",
                    111:                newError->where ? newError->where : "Unspecified");
                    112:     }
                    113: 
                    114:     /* Add to the stack in the request structure */
                    115:     if (!request->error_stack)
                    116:        request->error_stack = HTList_new();
                    117:     HTList_addObject(request->error_stack, (void *) newError);
2.4       frystyk   118:     return (-element);
2.1       frystyk   119: }
                    120: 
                    121: 
2.2       frystyk   122: /*                                                             HTErrorSysAdd
                    123: **
                    124: **     Add a system error message to the error list in HTRequest. syscall
                    125: **     is the name of the system call, e.g. "close". The message put to the
                    126: **     list is that corresponds to the errno. This function also replaces
                    127: **     HTInetStatus, which is called from within.
                    128: **
                    129: **     See also HTErrorAdd.
2.4       frystyk   130: **
                    131: **     Returns always < 0
2.2       frystyk   132: */
2.4       frystyk   133: PUBLIC int HTErrorSysAdd ARGS4(HTRequest *,    request,
                    134:                               HTErrSeverity,   severity,
                    135:                               BOOL,            ignore,
                    136:                               char *,          syscall)
2.2       frystyk   137: 
                    138: {
                    139:     HTErrorInfo *newError;
                    140:     if (!request) {
                    141:        if (TRACE) fprintf(stderr, "HTErrorSys.. Bad argument!\n");
2.4       frystyk   142:        return -1;
2.2       frystyk   143:     }
                    144:     if ((newError = (HTErrorInfo *) calloc(1, sizeof(HTErrorInfo))) == NULL)
2.7       luotonen  145:        outofmem(__FILE__, "HTErrorSysAdd");
2.2       frystyk   146:     newError->element = HTERR_SYSTEM;
                    147:     newError->severity = severity;
                    148:     newError->ignore = ignore;
                    149:     if (syscall) {
                    150:        newError->where = syscall;
                    151:        HTInetStatus(syscall);
                    152:     } else
                    153:        HTInetStatus("Unspecified System Call");
                    154:     {
2.7       luotonen  155:        char temp[100];
2.2       frystyk   156:        char *errmsg = NULL;
2.7       luotonen  157:        sprintf(temp, error_info[HTERR_SYSTEM].msg, syscall);
2.6       frystyk   158:        StrAllocCopy(errmsg, temp);
                    159:        StrAllocCat(errmsg, HTErrnoString());
2.2       frystyk   160:        newError->par = (void *) errmsg;
                    161:     }
                    162:     newError->par_length = (int) strlen(newError->par);
                    163:     if (TRACE) {
                    164:        fprintf(stderr, "System Error Code: %3d\tMessage: `%s\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
                    165:                error_info[newError->element].code,
                    166:                error_info[newError->element].msg,
                    167:                newError->severity,
                    168:                (char *) newError->par,
                    169:                newError->where ? newError->where : "Unspecified");
                    170:     }
                    171: 
                    172:     /* Add to the stack in the request structure */
                    173:     if (!request->error_stack)
                    174:        request->error_stack = HTList_new();
                    175:     HTList_addObject(request->error_stack, (void *) newError);
2.4       frystyk   176:     return (-HTERR_SYSTEM);
2.2       frystyk   177: }
                    178: 
                    179: 
2.1       frystyk   180: /*                                                             HTErrorFree
                    181: **
                    182: **     Free the whole error stack from the HTRequest structure.
                    183: */
                    184: PUBLIC void HTErrorFree ARGS1(HTRequest *, request)
                    185: {
                    186:     HTList *cur = request->error_stack;
                    187:     HTErrorInfo *pres;
                    188:     if (!request || !request->error_stack)
                    189:        return;
                    190:     while ((pres = (HTErrorInfo *) HTList_nextObject(cur))) {
                    191:        FREE(pres->par);
                    192:        free(pres);
                    193:     }
                    194:     HTList_delete(request->error_stack);
                    195:     request->error_stack = NULL;
                    196:     return;
                    197: }
                    198: 
                    199: 
                    200: /*                                                             HTErrorIgnore
                    201: **
                    202: **     Turns on the `ignore' flag for the most recent error entered the
                    203: **     error list. If the list is empty, nothing is done.
                    204: */
                    205: PUBLIC void HTErrorIgnore ARGS1(HTRequest *, request)
                    206: {
2.5       frystyk   207:     HTList *cur;
2.1       frystyk   208:     HTErrorInfo *pres;
                    209:     if (!request) {
                    210:        if (TRACE) fprintf(stderr, "HTErrorIgnore Bad argument!\n");
                    211:        return;
                    212:     }
2.5       frystyk   213:     cur = request->error_stack;
2.2       frystyk   214:     if (cur && (pres = (HTErrorInfo *) HTList_nextObject(cur)) != NULL) {
                    215:        if (TRACE)
                    216:            fprintf(stderr, "Error Ignore Code: %3d\tMessage: `%s\tSeverity: %d\tParameter: `%s\'\tWhere: `%s\'\n",
                    217:                    error_info[pres->element].code,
                    218:                    error_info[pres->element].msg,
                    219:                    pres->severity,
                    220:                    pres->par ? (char *) pres->par : "Unspecified",
                    221:                    pres->where ? pres->where : "Unspecified");
2.1       frystyk   222:        pres->ignore = YES;
2.2       frystyk   223:     }
2.1       frystyk   224:     return;
                    225: }
                    226: 
                    227: 
                    228: /*                                                             HTErrorMsg
                    229: **
2.4       frystyk   230: **     Creates an error message on standard output containing the 
                    231: **     error_stack messages. The HTErr 
2.1       frystyk   232: **     Only if the global variable HTErrorInfoPath != NULL, an anchor
2.4       frystyk   233: **     will be created to an message help file. It is garanteed that
                    234: **     NO STREAM has been put up or taken down in the library at this point.
                    235: **     This function might be overwritten by a smart server or client.
2.1       frystyk   236: */
2.2       frystyk   237: 
2.4       frystyk   238: /* *** LOOK IN HTML.C FOR ACTUAL IMPLEMENTATION OF THIS FUNCTION *** */
2.1       frystyk   239: 
                    240: /* END OF MODULE */
                    241: 
                    242: 
                    243: 
                    244: 
                    245: 

Webmaster