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

2.6       timbl       1: <HTML>
                      2: <HEAD>
2.63      frystyk     3: <TITLE>W3C Reference Library libwww BASIC MACROS</TITLE>
2.65      frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen, 11-Mar-1996 -->
2.6       timbl       5: </HEAD>
2.3       timbl       6: <BODY>
2.24      frystyk     7: 
2.56      frystyk     8: <H1>General Purpose Macros</H1>
2.20      frystyk     9: 
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>
                     16: 
                     17: This module is a part of the <A
2.44      frystyk    18: HREF="http://www.w3.org/pub/WWW/Library/"> W3C Reference Library</A>.
2.20      frystyk    19: 
2.62      frystyk    20: See also the system dependent file <A HREF="sysdep.html">tcp module</A>
2.26      frystyk    21: for system specific information. <P>
                     22: 
2.1       timbl      23: <PRE>
                     24: #ifndef HTUTILS_H
                     25: #define HTUTILS_H
2.56      frystyk    26: </PRE>
                     27: 
                     28: <A NAME="debug"><H2>Debug Message Control</H2></A>
2.20      frystyk    29: 
2.56      frystyk    30: This is the global flag for setting the WWWTRACE options. The verbose
                     31: mode is no longer a simple boolean but a bit field so that it is
                     32: possible to see parts of the output messages. 
2.20      frystyk    33: 
                     34: <PRE>
2.26      frystyk    35: #ifndef DEBUG
                     36: #define DEBUG  /* No one ever turns this off as trace is too important */
2.56      frystyk    37: #endif
                     38: </PRE>
                     39: 
                     40: <H3>Definition of the Global Trace Flag</H3>
2.26      frystyk    41: 
2.56      frystyk    42: The global trace flag variable is available everywhere.
                     43: 
                     44: <PRE>
                     45: #ifdef DEBUG
2.44      frystyk    46: #ifdef WWW_WIN_DLL
2.56      frystyk    47: extern int *           WWW_TraceFlag;   /* In DLLs, we need the indirection */
                     48: #define WWWTRACE       (*WWW_TraceFlag) 
2.44      frystyk    49: #else
2.56      frystyk    50: extern int             WWW_TraceFlag;       /* Global flag for all W3 trace */
                     51: #define WWWTRACE       (WWW_TraceFlag)
                     52: #endif /* WWW_WIN_DLL */
                     53: #else
                     54: #define WWWTRACE       0
                     55: #endif /* DEBUG */
2.20      frystyk    56: </PRE>
                     57: 
2.56      frystyk    58: The <EM>WWWTRACE</EM> define outputs messages if verbose mode is
                     59: active according to the following rules:
2.1       timbl      60: 
2.20      frystyk    61: <PRE>
2.56      frystyk    62: typedef enum _HTTraceFlags {
                     63:     SHOW_UTIL_TRACE    = 0x1,                          /*                 1 */
                     64:     SHOW_APP_TRACE     = 0x2,                          /*                10 */
                     65:     SHOW_CACHE_TRACE   = 0x4,                          /*               100 */
                     66:     SHOW_SGML_TRACE    = 0x8,                          /*              1000 */
                     67:     SHOW_BIND_TRACE    = 0x10,                         /*            1.0000 */
                     68:     SHOW_THREAD_TRACE  = 0x20,                         /*           10.0000 */
                     69:     SHOW_STREAM_TRACE  = 0x40,                         /*          100.0000 */
                     70:     SHOW_PROTOCOL_TRACE = 0x80,                                /*         1000.0000 */
2.57      frystyk    71:     SHOW_MEM_TRACE     = 0x100,                        /*       1.0000.0000 */
2.56      frystyk    72:     SHOW_URI_TRACE     = 0x200,                        /*      10.0000.0000 */
2.61      frystyk    73:     SHOW_AUTH_TRACE    = 0x400,                        /*    1.00.0000.0000 */
2.56      frystyk    74:     SHOW_ANCHOR_TRACE  = 0x800,                        /*   10.00.0000.0000 */
                     75:     SHOW_ALL_TRACE     = 0xFFF                         /*   11.11.1111.1111 */
                     76: } HTTraceFlags;
                     77: </PRE>
                     78: 
                     79: The flags are made so that they can serve as a group flag for
                     80: correlated trace messages, e.g. showing messages for SGML and HTML at
                     81: the same time.
                     82: 
                     83: <PRE>
                     84: #define UTIL_TRACE     (WWWTRACE & SHOW_UTIL_TRACE)
                     85: #define APP_TRACE      (WWWTRACE & SHOW_APP_TRACE)
                     86: #define CACHE_TRACE    (WWWTRACE & SHOW_CACHE_TRACE)
                     87: #define SGML_TRACE     (WWWTRACE & SHOW_SGML_TRACE)
                     88: #define BIND_TRACE     (WWWTRACE & SHOW_BIND_TRACE)
                     89: #define THD_TRACE      (WWWTRACE & SHOW_THREAD_TRACE)
                     90: #define STREAM_TRACE   (WWWTRACE & SHOW_STREAM_TRACE)
                     91: #define PROT_TRACE     (WWWTRACE & SHOW_PROTOCOL_TRACE)
2.57      frystyk    92: #define MEM_TRACE      (WWWTRACE & SHOW_MEM_TRACE)
2.56      frystyk    93: #define URI_TRACE      (WWWTRACE & SHOW_URI_TRACE)
2.61      frystyk    94: #define AUTH_TRACE     (WWWTRACE & SHOW_AUTH_TRACE)
2.56      frystyk    95: #define ANCH_TRACE     (WWWTRACE & SHOW_ANCHOR_TRACE)
                     96: </PRE>
                     97: 
2.59      frystyk    98: <H3>Destination for Trace Messages</H3>
                     99: 
                    100: You can send trace messages to various destinations depending on the
                    101: type of your application. By default, on Unix the messages are sent to
                    102: stderr using fprintf() and if we are on Windows and have a windows
                    103: applications then register a HTTraceCallback function. This is done with
                    104: HTTrace_setCallback. It tells HTTrace to call a HTTraceCallback. If your 
                    105: compiler has problems with va_list, then you may forget about registering 
                    106: the callback and instead macro HTTrace as follows:
                    107: #define HTTrace MyAppSpecificTrace
                    108: 
                    109: <PRE>
2.62      frystyk   110: typedef int HTTraceCallback(const char * fmt, va_list pArgs);
2.59      frystyk   111: 
                    112: extern void HTTrace_setCallback(HTTraceCallback * pCall);
                    113: extern HTTraceCallback * HTTrace_getCallback(void);
                    114: 
2.62      frystyk   115: extern int HTTrace(const char * fmt, ...);
2.26      frystyk   116: </PRE>
                    117: 
2.56      frystyk   118: <A NAME="declaration"><H2>Macros for Function Declarations</H2></A>
2.26      frystyk   119: 
                    120: <PRE>
                    121: #define PUBLIC                 /* Accessible outside this module     */
2.1       timbl     122: #define PRIVATE static         /* Accessible only within this module */
2.56      frystyk   123: </PRE>
                    124: 
                    125: <H2>Often used Interger Macros</H2>
2.1       timbl     126: 
2.56      frystyk   127: <H3>Min and Max functions</H3>
                    128: 
                    129: <PRE>
2.11      timbl     130: #ifndef HTMIN 
                    131: #define HTMIN(a,b) ((a) &lt;= (b) ? (a) : (b))
                    132: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1       timbl     133: #endif
2.26      frystyk   134: </PRE>
2.1       timbl     135: 
2.56      frystyk   136: <H3>Double abs function</H3>
                    137: 
                    138: <PRE>
                    139: #ifndef HTDABS
                    140: #define HTDABS(a) ((a) &lt; 0.0 ? (-(a)) : (a))
                    141: #endif
                    142: </PRE>
                    143: 
2.35      frystyk   144: <A NAME="ReturnCodes"><H2>Return Codes for Protocol Modules and Streams</H2></A>
                    145: 
                    146: Theese are the codes returned from the protocol modules, and the
                    147: stream modules. Success are (&gt;=0) and failure are (&lt;0)
2.1       timbl     148: 
2.3       timbl     149: <PRE>
2.23      frystyk   150: #define HT_OK                  0       /* Generic success */
2.37      frystyk   151: #define HT_ALL                 1       /* Used by Net Manager */
                    152: 
2.53      frystyk   153: #define HT_CLOSED              29992   /* The socket was closed */
2.52      frystyk   154: #define HT_PERSISTENT          29993   /* Wait for persistent connection */
                    155: #define HT_IGNORE              29994   /* Ignore this in the Net manager */
                    156: #define HT_NO_DATA             29995   /* OK but no data was loaded */
2.53      frystyk   157: #define HT_RELOAD              29996   /* If we must reload the document */
2.52      frystyk   158: #define HT_PERM_REDIRECT       29997   /* Redo the retrieve with a new URL */
                    159: #define HT_TEMP_REDIRECT       29998   /* Redo the retrieve with a new URL */
2.23      frystyk   160: #define HT_LOADED              29999   /* Instead of a socket */
                    161: 
                    162: #define HT_ERROR               -1      /* Generic failure */
2.53      frystyk   163: 
2.23      frystyk   164: #define HT_NO_ACCESS           -10     /* Access not available */
                    165: #define HT_FORBIDDEN           -11     /* Access forbidden */
2.53      frystyk   166: #define HT_RETRY               -13     /* If service isn't available */
                    167: 
                    168: #define HT_INTERNAL            -100    /* Weird -- should never happen. */
2.35      frystyk   169: 
2.23      frystyk   170: #define HT_WOULD_BLOCK         -29997  /* If we are in a select */
2.15      frystyk   171: #define HT_INTERRUPTED                 -29998  /* Note the negative value! */
2.53      frystyk   172: #define HT_PAUSE                -29999  /* If we want to pause a stream */
2.35      frystyk   173: </PRE>
                    174: 
2.26      frystyk   175: <H2>Upper- and Lowercase macros</H2>
                    176: 
                    177: The problem here is that toupper(x) is not defined officially unless
                    178: isupper(x) is.  These macros are CERTAINLY needed on #if defined(pyr)
                    179: || define(mips) or BDSI platforms. For safefy, we make them mandatory.
2.1       timbl     180: 
2.25      roeber    181: <PRE>
2.1       timbl     182: #ifndef TOLOWER
2.27      frystyk   183: #define TOLOWER(c) tolower(c)
                    184: #define TOUPPER(c) toupper(c)
2.29      frystyk   185: #endif
                    186: </PRE>
                    187: 
                    188: <H2>Max and Min values for Integers and Floating Point</H2>
                    189: 
                    190: <PRE>
                    191: #ifdef FLT_EPSILON                                 /* The ANSI C way define */
                    192: #define HT_EPSILON FLT_EPSILON
                    193: #else
                    194: #define HT_EPSILON 0.00000001
2.27      frystyk   195: #endif
                    196: </PRE>
                    197: 
                    198: <H2>White Characters</H2>
                    199: 
                    200: Is character <B>c</B> white space?
                    201: 
                    202: <PRE>
                    203: #define WHITE(c) isspace(c)
2.26      frystyk   204: </PRE>
                    205: 
                    206: <H2>The local equivalents of CR and LF</H2>
2.1       timbl     207: 
2.26      frystyk   208: We can check for these after net ascii text has been converted to the
                    209: local representation. Similarly, we include them in strings to be sent
                    210: as net ascii after translation.
                    211: 
                    212: <PRE>
                    213: #define LF   FROMASCII('\012')  /* ASCII line feed LOCAL EQUIVALENT */
                    214: #define CR   FROMASCII('\015')  /* Will be converted to ^M for transmission */
2.54      frystyk   215: </PRE>
                    216: 
                    217: <H2>Library Dynamic Memory Magement</H2>
                    218: 
                    219: The Library has it's own dynamic memory API which is declared in <A
                    220: HREF="HTMemory.html">memory management module</A>.
                    221: 
                    222: <PRE>
2.55      frystyk   223: #include "HTMemory.h"
2.26      frystyk   224: </PRE>
2.1       timbl     225: 
2.56      frystyk   226: <PRE>
                    227: #endif /* HT_UTILS.h */
                    228: </PRE>
                    229: 
                    230: End of utility declarations
2.26      frystyk   231: </BODY>
2.6       timbl     232: </HTML>

Webmaster