Annotation of libwww/Library/src/HTUtils.html, revision 2.75

2.6       timbl       1: <HTML>
                      2: <HEAD>
2.69      frystyk     3:   <!-- Changed by: Henrik Frystyk Nielsen,  6-Apr-1996 -->
                      4:   <TITLE>W3C Reference Library libwww General Purpose Macros</TITLE>
2.6       timbl       5: </HEAD>
2.3       timbl       6: <BODY>
2.69      frystyk     7: <H1>
                      8:   General Purpose Macros
                      9: </H1>
2.24      frystyk    10: <PRE>
                     11: /*
2.31      frystyk    12: **     (c) COPYRIGHT MIT 1995.
2.24      frystyk    13: **     Please first read the full copyright statement in the file COPYRIGH.
                     14: */
                     15: </PRE>
2.69      frystyk    16: <P>
                     17: This module is a part of the <A HREF="http://www.w3.org/pub/WWW/Library/">
                     18: W3C Reference Library</A>. See also the system dependent file
                     19: <A HREF="sysdep.html">sysdep module</A> for system specific information.
2.1       timbl      20: <PRE>
                     21: #ifndef HTUTILS_H
                     22: #define HTUTILS_H
2.56      frystyk    23: </PRE>
2.69      frystyk    24: <H2>
2.71      frystyk    25:   <A NAME="Debug">Debug Message Control</A>
2.69      frystyk    26: </H2>
                     27: <P>
                     28: This is the global flag for setting the <CODE>WWWTRACE</CODE> options. The
                     29: verbose mode is no longer a simple boolean but a bit field so that it is
                     30: possible to see parts of the output messages.
2.20      frystyk    31: <PRE>
2.26      frystyk    32: #ifndef DEBUG
                     33: #define DEBUG  /* No one ever turns this off as trace is too important */
2.56      frystyk    34: #endif
                     35: </PRE>
2.69      frystyk    36: <H3>
                     37:   Definition of the Global Trace Flag
                     38: </H3>
                     39: <P>
2.56      frystyk    40: The global trace flag variable is available everywhere.
                     41: <PRE>
                     42: #ifdef DEBUG
2.44      frystyk    43: #ifdef WWW_WIN_DLL
2.56      frystyk    44: extern int *           WWW_TraceFlag;   /* In DLLs, we need the indirection */
                     45: #define WWWTRACE       (*WWW_TraceFlag) 
2.44      frystyk    46: #else
2.56      frystyk    47: extern int             WWW_TraceFlag;       /* Global flag for all W3 trace */
                     48: #define WWWTRACE       (WWW_TraceFlag)
                     49: #endif /* WWW_WIN_DLL */
                     50: #else
                     51: #define WWWTRACE       0
                     52: #endif /* DEBUG */
2.20      frystyk    53: </PRE>
2.69      frystyk    54: <P>
                     55: The <EM><CODE>WWWTRACE</CODE></EM> define outputs messages if verbose mode
                     56: is active according to the following rules:
2.20      frystyk    57: <PRE>
2.56      frystyk    58: typedef enum _HTTraceFlags {
                     59:     SHOW_UTIL_TRACE    = 0x1,                          /*                 1 */
                     60:     SHOW_APP_TRACE     = 0x2,                          /*                10 */
                     61:     SHOW_CACHE_TRACE   = 0x4,                          /*               100 */
                     62:     SHOW_SGML_TRACE    = 0x8,                          /*              1000 */
                     63:     SHOW_BIND_TRACE    = 0x10,                         /*            1.0000 */
                     64:     SHOW_THREAD_TRACE  = 0x20,                         /*           10.0000 */
                     65:     SHOW_STREAM_TRACE  = 0x40,                         /*          100.0000 */
                     66:     SHOW_PROTOCOL_TRACE = 0x80,                                /*         1000.0000 */
2.57      frystyk    67:     SHOW_MEM_TRACE     = 0x100,                        /*       1.0000.0000 */
2.56      frystyk    68:     SHOW_URI_TRACE     = 0x200,                        /*      10.0000.0000 */
2.67      hallam     69:     SHOW_AUTH_TRACE    = 0x400,                        /*     100.0000.0000 */
                     70:     SHOW_ANCHOR_TRACE  = 0x800,                        /*    1000.0000.0000 */
                     71:     SHOW_PICS_TRACE    = 0x1000,                       /*  1.0000.0000.0000 */
                     72:     SHOW_CORE_TRACE    = 0x2000,                       /* 10.0000.0000.0000 */
                     73:     SHOW_ALL_TRACE     = 0x3FFF                        /* 11.1111.1111.1111 */
2.56      frystyk    74: } HTTraceFlags;
                     75: </PRE>
2.69      frystyk    76: <P>
                     77: The flags are made so that they can serve as a group flag for correlated
                     78: trace messages, e.g. showing messages for SGML and HTML at the same time.
                     79: <PRE>
                     80: #define UTIL_TRACE     (WWWTRACE &amp; SHOW_UTIL_TRACE)
                     81: #define APP_TRACE      (WWWTRACE &amp; SHOW_APP_TRACE)
                     82: #define CACHE_TRACE    (WWWTRACE &amp; SHOW_CACHE_TRACE)
                     83: #define SGML_TRACE     (WWWTRACE &amp; SHOW_SGML_TRACE)
                     84: #define BIND_TRACE     (WWWTRACE &amp; SHOW_BIND_TRACE)
                     85: #define THD_TRACE      (WWWTRACE &amp; SHOW_THREAD_TRACE)
                     86: #define STREAM_TRACE   (WWWTRACE &amp; SHOW_STREAM_TRACE)
                     87: #define PROT_TRACE     (WWWTRACE &amp; SHOW_PROTOCOL_TRACE)
                     88: #define MEM_TRACE      (WWWTRACE &amp; SHOW_MEM_TRACE)
                     89: #define URI_TRACE      (WWWTRACE &amp; SHOW_URI_TRACE)
                     90: #define AUTH_TRACE     (WWWTRACE &amp; SHOW_AUTH_TRACE)
                     91: #define ANCH_TRACE     (WWWTRACE &amp; SHOW_ANCHOR_TRACE)
                     92: #define PICS_TRACE     (WWWTRACE &amp; SHOW_PICS_TRACE)
                     93: #define CORE_TRACE     (WWWTRACE &amp; SHOW_CORE_TRACE)
                     94: </PRE>
                     95: <H3>
                     96:   Destination for Trace Messages
                     97: </H3>
                     98: <P>
                     99: You can send trace messages to various destinations depending on the type
                    100: of your application. By default, on Unix the messages are sent to stderr
                    101: using fprintf() and if we are on Windows and have a windows applications
                    102: then register a HTTraceCallback function. This is done with HTTrace_setCallback.
                    103: It tells HTTrace to call a HTTraceCallback. If your compiler has problems
                    104: with va_list, then you may forget about registering the callback and instead
                    105: macro HTTrace as follows: #define HTTrace MyAppSpecificTrace
2.67      hallam    106: <A NAME="HTTrace"></A>
2.59      frystyk   107: <PRE>
2.62      frystyk   108: typedef int HTTraceCallback(const char * fmt, va_list pArgs);
2.59      frystyk   109: 
                    110: extern void HTTrace_setCallback(HTTraceCallback * pCall);
                    111: extern HTTraceCallback * HTTrace_getCallback(void);
                    112: 
2.62      frystyk   113: extern int HTTrace(const char * fmt, ...);
2.26      frystyk   114: </PRE>
2.69      frystyk   115: <H2>
                    116:   Macros for Function Declarations
                    117: </H2>
2.26      frystyk   118: <PRE>
                    119: #define PUBLIC                 /* Accessible outside this module     */
2.1       timbl     120: #define PRIVATE static         /* Accessible only within this module */
2.56      frystyk   121: </PRE>
2.69      frystyk   122: <H2>
                    123:   Often used Interger Macros
                    124: </H2>
                    125: <H3>
                    126:   Min and Max functions
                    127: </H3>
2.56      frystyk   128: <PRE>
2.11      timbl     129: #ifndef HTMIN 
                    130: #define HTMIN(a,b) ((a) &lt;= (b) ? (a) : (b))
2.69      frystyk   131: #define HTMAX(a,b) ((a) &gt;= (b) ? (a) : (b))
2.1       timbl     132: #endif
2.26      frystyk   133: </PRE>
2.69      frystyk   134: <H3>
                    135:   Double abs function
                    136: </H3>
2.56      frystyk   137: <PRE>
                    138: #ifndef HTDABS
                    139: #define HTDABS(a) ((a) &lt; 0.0 ? (-(a)) : (a))
                    140: #endif
                    141: </PRE>
2.69      frystyk   142: <P>
                    143: <A NAME="ReturnCodes"></A>
                    144: <H2>
2.70      frystyk   145:   <A NAME="return">Return Codes for Protocol Modules and Streams</A>
2.69      frystyk   146: </H2>
                    147: <P>
                    148: Theese are the codes returned from the protocol modules, and the stream modules.
                    149: Success are (&gt;=0) and failure are (&lt;0)
2.3       timbl     150: <PRE>
2.23      frystyk   151: #define HT_OK                  0       /* Generic success */
2.37      frystyk   152: #define HT_ALL                 1       /* Used by Net Manager */
                    153: 
2.75    ! frystyk   154: #define HT_CONTINUE             100     /* Continue an operation */
        !           155: #define HT_UPGRADE              101     /* Switching protocols */
        !           156: 
        !           157: #define HT_LOADED              200     /* Everything's OK */
        !           158: #define HT_CREATED             201     /* New object is created */
        !           159: #define HT_ACCEPTED            202     /* Accepted */
        !           160: #define HT_NO_DATA             204     /* OK but no data was loaded */
        !           161: #define HT_RESET_CONTENT        205     /* Reset content */
        !           162: #define HT_PARTIAL_CONTENT     206     /* Partial Content */
        !           163: 
        !           164: #define HT_MULTIPLE_CHOICES     300     /* Multiple choices */
        !           165: #define HT_PERM_REDIRECT       301     /* Permanent redirection */
        !           166: #define HT_TEMP_REDIRECT       302     /* Temporary redirection */
        !           167: #define HT_SEE_OTHER            303     /* See other */
        !           168: #define HT_NOT_MODIFIED         304     /* Not Modified */
        !           169: #define HT_USE_PROXY            305     /* Use Proxy */
        !           170: 
        !           171: #define HT_IGNORE              900     /* Ignore this in the Net manager */
        !           172: #define HT_CLOSED              901     /* The socket was closed */
        !           173: #define HT_PENDING             902     /* Wait for connection */
        !           174: #define HT_RELOAD              903     /* If we must reload the document */
2.23      frystyk   175: 
                    176: #define HT_ERROR               -1      /* Generic failure */
2.53      frystyk   177: 
2.75    ! frystyk   178: #define HT_NO_ACCESS           -401    /* Unauthorized */
        !           179: #define HT_FORBIDDEN           -403    /* Access forbidden */
        !           180: #define HT_NOT_ACCEPTABLE      -406    /* Not Acceptable */
        !           181: #define HT_NO_PROXY_ACCESS      -407    /* Proxy Authentication Failed */
        !           182: #define HT_CONFLICT             -409    /* Conflict */
        !           183: #define HT_LENGTH_REQUIRED      -411    /* Length required */
        !           184: 
        !           185: #define HT_RETRY               -503    /* If service isn't available */
        !           186: #define HT_BAD_VERSION         -505    /* Bad protocol version */
        !           187: 
        !           188: #define HT_INTERNAL            -900    /* Weird -- should never happen. */
        !           189: #define HT_WOULD_BLOCK         -901    /* If we are in a select */
        !           190: #define HT_INTERRUPTED                 -902    /* Note the negative value! */
        !           191: #define HT_PAUSE                -903    /* If we want to pause a stream */
        !           192: #define HT_RECOVER_PIPE         -904    /* Recover pipe line */
2.35      frystyk   193: </PRE>
2.69      frystyk   194: <H2>
                    195:   Upper- and Lowercase macros
                    196: </H2>
                    197: <P>
                    198: The problem here is that toupper(x) is not defined officially unless isupper(x)
                    199: is. These macros are CERTAINLY needed on #if defined(pyr) || define(mips)
                    200: or BDSI platforms. For safefy, we make them mandatory.
2.25      roeber    201: <PRE>
2.1       timbl     202: #ifndef TOLOWER
2.27      frystyk   203: #define TOLOWER(c) tolower(c)
                    204: #define TOUPPER(c) toupper(c)
2.29      frystyk   205: #endif
                    206: </PRE>
2.69      frystyk   207: <H2>
                    208:   Max and Min values for Integers and Floating Point
                    209: </H2>
2.29      frystyk   210: <PRE>
                    211: #ifdef FLT_EPSILON                                 /* The ANSI C way define */
                    212: #define HT_EPSILON FLT_EPSILON
                    213: #else
                    214: #define HT_EPSILON 0.00000001
2.27      frystyk   215: #endif
                    216: </PRE>
2.69      frystyk   217: <H2>
                    218:   White Characters
                    219: </H2>
                    220: <P>
2.27      frystyk   221: Is character <B>c</B> white space?
                    222: <PRE>
                    223: #define WHITE(c) isspace(c)
2.26      frystyk   224: </PRE>
2.69      frystyk   225: <H2>
                    226:   The local equivalents of CR and LF
                    227: </H2>
                    228: <P>
                    229: We can check for these after net ascii text has been converted to the local
                    230: representation. Similarly, we include them in strings to be sent as net ascii
                    231: after translation.
2.26      frystyk   232: <PRE>
                    233: #define LF   FROMASCII('\012')  /* ASCII line feed LOCAL EQUIVALENT */
                    234: #define CR   FROMASCII('\015')  /* Will be converted to ^M for transmission */
2.54      frystyk   235: </PRE>
2.69      frystyk   236: <H2>
                    237:   Library Dynamic Memory Magement
                    238: </H2>
                    239: <P>
                    240: The Library has it's own dynamic memory API which is declared in
                    241: <A HREF="HTMemory.html">memory management module</A>.
2.54      frystyk   242: <PRE>
2.55      frystyk   243: #include "HTMemory.h"
2.26      frystyk   244: </PRE>
2.56      frystyk   245: <PRE>
                    246: #endif /* HT_UTILS.h */
                    247: </PRE>
2.69      frystyk   248: <P>
                    249:   <HR>
2.68      frystyk   250: <ADDRESS>
2.75    ! frystyk   251:   @(#) $Id: HTUtils.html,v 2.74 1996/08/19 18:31:23 frystyk Exp $
2.68      frystyk   252: </ADDRESS>
2.69      frystyk   253: </BODY></HTML>

Webmaster