Annotation of libwww/Library/src/HTFWrite.html, revision 2.6

2.1       frystyk     1: <HTML>
                      2: <HEAD>
2.2       frystyk     3: <TITLE>Cache Manager and Writing to a File using ANSI C</TITLE>
2.6     ! frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen, 28-Jun-1995 -->
2.1       frystyk     5: <NEXTID N="z4">
                      6: </HEAD>
                      7: <BODY>
                      8: 
2.2       frystyk     9: <H1>Cache Manager and Writing to a File using ANSI C</H1>
2.1       frystyk    10: 
                     11: <PRE>
                     12: /*
2.4       frystyk    13: **     (c) COPYRIGHT MIT 1995.
2.1       frystyk    14: **     Please first read the full copyright statement in the file COPYRIGH.
                     15: */
                     16: </PRE>
                     17: 
                     18: It is useful to have both FWriter and Writer for environments in which
2.2       frystyk    19: <CODE>fdopen()</CODE> doesn't exist for example. The module contains
                     20: the following parts:
                     21: 
                     22: <UL>
                     23: <LI><A HREF="#BlackHole">A Balckhole for absorbing data</A>
                     24: <LI><A HREF="#write">A File Writer Stream</A>
                     25: <LI><A HREF="#converters">Converters using the file writer stream</A>
                     26: <LI><A HREF="#z3">Cache Manager</A>
                     27: </UL>
                     28: 
2.1       frystyk    29: 
                     30: This module is implemented by <A HREF="HTFWrite.c">HTFWrite.c</A>,
                     31: and it is a part of the <A
2.2       frystyk    32: HREF="http://www.w3.org/hypertext/WWW/Library/User/Guide/Guide.html">
2.1       frystyk    33: Library of Common Code</A>.
                     34: 
                     35: 
                     36: <PRE>
                     37: #ifndef HTFWRITE_H
                     38: #define HTFWRITE_H
                     39: 
                     40: #include "HTStream.h"
                     41: #include "HTFormat.h"
                     42: </PRE>
                     43: 
2.2       frystyk    44: <H2><A NAME="BlackHole">Black Hole Stream</A></H2>
                     45: 
                     46: This stream simply absorbs data without doing anything what so ever.
                     47: 
                     48: <PRE>
                     49: extern HTStream * HTBlackHole NOPARAMS;
                     50: </PRE>
                     51: 
2.5       frystyk    52: <A NAME="converters"><H2>Converters</H2></A>
2.1       frystyk    53: 
2.5       frystyk    54: This is the set of functions that can be registered as
                     55: converters. Note that the cache writer stream is also a converter!
2.1       frystyk    56: 
2.5       frystyk    57: <PRE>
                     58: #ifndef pyramid
                     59: extern HTConverter HTSaveAndExecute, HTSaveLocally, HTSaveAndCallBack,
                     60:        HTThroughLine, HTCacheWriter;
                     61: #endif
2.1       frystyk    62: </PRE>
                     63: 
2.5       frystyk    64: <A NAME="tmp"><H2>Location of Temporary Files</H2></A>
2.1       frystyk    65: 
2.2       frystyk    66: <CODE>HTSaveAndCallBack</CODE> will save to a cache file and call the
                     67: request-&gt;callback function with the filename as parameter. The
                     68: destination for temporary files can be managed by the following
                     69: functions:
                     70: 
                     71: <PRE>
                     72: extern BOOL  HTTmp_setRoot             PARAMS((CONST char * tmp_root));
                     73: extern CONST char * HTTmp_getRoot      NOPARAMS;
                     74: extern void  HTTmp_freeRoot            NOPARAMS;
                     75: </PRE>
                     76: 
                     77: The <CODE>HTTmp_freeRoot</CODE> is called by the <A
2.5       frystyk    78: HREF="HTAccess.html#Library">HTLibTerminate</A> function. The default
                     79: value is defined in <A
                     80: HREF="HTAccess.html#Addresses">HTAccess.html</A>
2.1       frystyk    81: 
2.5       frystyk    82: <H2><A NAME="write">Set up a Stream to a File</A></H2>
2.1       frystyk    83: 
2.5       frystyk    84: This function puts up a new stream given an open file descripter. If the file
                     85: is not to be closed afterwards, then set leave_open = NO.
2.1       frystyk    86: 
2.5       frystyk    87: <PRE>extern HTStream * HTFWriter_new PARAMS((FILE *    fp,
                     88:                                             BOOL       leave_open));
2.1       frystyk    89: </PRE>
                     90: 
2.2       frystyk    91: <H2><A NAME="z3">The Cache Manager</A></H2>
2.1       frystyk    92: 
2.2       frystyk    93: The cache contains details of temporary disk files which contain the
                     94: contents of remote documents.  There is also a <A NAME="z2"
                     95: HREF="HTAnchor.html#z1">list of cache items for each URL</A> in its
                     96: anchor object.
2.1       frystyk    97: 
2.6     ! frystyk    98: <A NAME="cacheitem"><H3>An item in the cache</H3></A>
2.2       frystyk    99: 
                    100: This will not be public in the next release so <B>DON'T USE IT ;-)</B>
                    101: 
2.1       frystyk   102: <PRE>typedef struct _HTCacheItem {
                    103:     HTParentAnchor *   anchor;
                    104:     HTFormat           format;         /* May have many formats per anchor */
                    105:     char *             filename;
                    106:     time_t             load_time;
                    107:     time_t             load_delay;
                    108:     int                        reference_count;
                    109: } HTCacheItem;
2.2       frystyk   110: </PRE>
                    111: 
                    112: <H3>The Cache Limit</H3>
2.1       frystyk   113: 
2.2       frystyk   114: The cache limit is the number of files which are kept. Yes, I know,
2.6     ! frystyk   115: the amount of disk space would be more relevant. So this may change.
2.2       frystyk   116: Currently it is preset to 100 but may be changed by the application by
                    117: writing into this variable.
                    118: 
                    119: <PRE>
                    120: extern int HTCacheLimit;
2.1       frystyk   121: </PRE>
                    122: 
2.2       frystyk   123: <H3>Enable Cache</H3>
                    124: 
                    125: If <EM>cache_root</EM> is NULL then reuse old value or use
                    126: <CODE>HT_CACHE_ROOT</CODE>.  An empty string will make '/' as cache
                    127: root.
                    128: 
                    129: <PRE>
                    130: extern BOOL HTCache_enable PARAMS((CONST char * cache_root));
2.1       frystyk   131: </PRE>
                    132: 
2.2       frystyk   133: <H3>Disable Cache</H3>
                    134: 
                    135: Turns off the cache. Note that the cache can be disabled and enabled
                    136: at any time. The cache root is kept and can be reused during the
                    137: execution.
                    138: 
                    139: <PRE>
                    140: extern BOOL HTCache_disable NOPARAMS;
                    141: </PRE>
                    142: 
                    143: <H3>Is Cache Enabled</H3>
                    144: 
                    145: Returns YES or NO. Also makes sure that we have a root value (even
                    146: though it might be invalid)
                    147: 
                    148: <PRE>
                    149: extern BOOL HTCache_isEnabled NOPARAMS;
                    150: </PRE>
                    151: 
                    152: <H3>Set Cache Root</H3>
                    153: 
                    154: If <EM>cache_root</EM> is NULL then the current value (might be a define)
                    155: Should we check if the cache_root is actually OK? I think not!
                    156: 
                    157: <PRE>
                    158: extern BOOL HTCache_setRoot PARAMS((CONST char * cache_root));
                    159: </PRE>
                    160: 
                    161: 
                    162: <H3>Get Cache Root</H3>
                    163: 
                    164: <PRE>
                    165: extern CONST char *HTCache_getRoot NOPARAMS;
2.1       frystyk   166: </PRE>
                    167: 
2.2       frystyk   168: <H3>For clean up memory</H3>
                    169: 
                    170: This is done by the Library function <A
                    171: HREF="HTAccess.html#Library">HTLibTerminate()</A>
                    172: 
                    173: <PRE>
                    174: extern void HTCache_freeRoot NOPARAMS;
2.1       frystyk   175: </PRE>
2.2       frystyk   176: 
                    177: <H3>Clear a cache</H3>
                    178: 
                    179: Can clear a list of cache items.
                    180: 
2.1       frystyk   181: <PRE>
2.2       frystyk   182: extern void HTCacheClear PARAMS((HTList * cache));
2.1       frystyk   183: </PRE>
                    184: 
2.2       frystyk   185: <H3>To remove All cache files known to this session</H3>
2.1       frystyk   186: 
                    187: <PRE>
2.2       frystyk   188: extern void HTCacheDeleteAll NOPARAMS;
2.1       frystyk   189: 
                    190: #endif
                    191: </PRE>
                    192: 
                    193: End of definition module
                    194: </BODY>
                    195: </HTML>

Webmaster