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

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

Webmaster