File:  [Public] / libwww / Library / src / HTFWrite.html
Revision 2.4: download - view: text, annotated - select for diffs
Fri May 19 02:05:01 1995 UTC (29 years, 1 month ago) by frystyk
Branches: MAIN
CVS tags: v3/1pre1, WinNT, HEAD
final swap to MIT statements

<HTML>
<HEAD>
<TITLE>Cache Manager and Writing to a File using ANSI C</TITLE>
<NEXTID N="z4">
</HEAD>
<BODY>

<H1>Cache Manager and Writing to a File using ANSI C</H1>

<PRE>
/*
**	(c) COPYRIGHT MIT 1995.
**	Please first read the full copyright statement in the file COPYRIGH.
*/
</PRE>

It is useful to have both FWriter and Writer for environments in which
<CODE>fdopen()</CODE> doesn't exist for example. The module contains
the following parts:

<UL>
<LI><A HREF="#BlackHole">A Balckhole for absorbing data</A>
<LI><A HREF="#write">A File Writer Stream</A>
<LI><A HREF="#converters">Converters using the file writer stream</A>
<LI><A HREF="#z3">Cache Manager</A>
</UL>


This module is implemented by <A HREF="HTFWrite.c">HTFWrite.c</A>,
and it is a part of the <A
HREF="http://www.w3.org/hypertext/WWW/Library/User/Guide/Guide.html">
Library of Common Code</A>.


<PRE>
#ifndef HTFWRITE_H
#define HTFWRITE_H

#include "HTStream.h"
#include "HTFormat.h"
</PRE>

<H2><A NAME="BlackHole">Black Hole Stream</A></H2>

This stream simply absorbs data without doing anything what so ever.

<PRE>
extern HTStream * HTBlackHole NOPARAMS;
</PRE>

<H2><A NAME="write">Set up a Stream to a File</A></H2>

This function puts up a new stream given an open file descripter. If the file
is not to be closed afterwards, then set leave_open = NO.

<PRE>extern HTStream * HTFWriter_new PARAMS((FILE *	fp,
					     BOOL	leave_open));
</PRE>

<A NAME="converters"><H2>Converters</H2></A>

<CODE>HTSaveAndCallBack</CODE> will save to a cache file and call the
request-&gt;callback function with the filename as parameter. The
destination for temporary files can be managed by the following
functions:

<PRE>
extern BOOL  HTTmp_setRoot		PARAMS((CONST char * tmp_root));
extern CONST char * HTTmp_getRoot	NOPARAMS;
extern void  HTTmp_freeRoot		NOPARAMS;
</PRE>

The <CODE>HTTmp_freeRoot</CODE> is called by the <A
HREF="HTAccess.html#Library">HTLibTerminate</A> function

<PRE>
#ifndef pyramid
extern HTConverter HTSaveAndExecute, HTSaveLocally, HTSaveAndCallBack,
       HTThroughLine;
#endif
</PRE>

<H3>Stream for writing to cache</H3>

Note that HTSaveAndCallBack will also generate a cache file.

<PRE>
#ifndef pyramid
extern HTConverter HTCacheWriter;
#endif
</PRE>

<H2><A NAME="z3">The Cache Manager</A></H2>

The cache contains details of temporary disk files which contain the
contents of remote documents.  There is also a <A NAME="z2"
HREF="HTAnchor.html#z1">list of cache items for each URL</A> in its
anchor object.

<H3>An item in the cache</H3>

This will not be public in the next release so <B>DON'T USE IT ;-)</B>

<PRE>typedef struct _HTCacheItem {
    HTParentAnchor *	anchor;
    HTFormat		format;		/* May have many formats per anchor */
    char *		filename;
    time_t		load_time;
    time_t		load_delay;
    int			reference_count;
} HTCacheItem;
</PRE>

<H3>The Cache Limit</H3>

The cache limit is the number of files which are kept. Yes, I know,
the amount of disk space wouldbe more relevant. So this may change.
Currently it is preset to 100 but may be changed by the application by
writing into this variable.

<PRE>
extern int HTCacheLimit;
</PRE>

<H3>Enable Cache</H3>

If <EM>cache_root</EM> is NULL then reuse old value or use
<CODE>HT_CACHE_ROOT</CODE>.  An empty string will make '/' as cache
root.

<PRE>
extern BOOL HTCache_enable PARAMS((CONST char * cache_root));
</PRE>

<H3>Disable Cache</H3>

Turns off the cache. Note that the cache can be disabled and enabled
at any time. The cache root is kept and can be reused during the
execution.

<PRE>
extern BOOL HTCache_disable NOPARAMS;
</PRE>

<H3>Is Cache Enabled</H3>

Returns YES or NO. Also makes sure that we have a root value (even
though it might be invalid)

<PRE>
extern BOOL HTCache_isEnabled NOPARAMS;
</PRE>

<H3>Set Cache Root</H3>

If <EM>cache_root</EM> is NULL then the current value (might be a define)
Should we check if the cache_root is actually OK? I think not!

<PRE>
extern BOOL HTCache_setRoot PARAMS((CONST char * cache_root));
</PRE>


<H3>Get Cache Root</H3>

<PRE>
extern CONST char *HTCache_getRoot NOPARAMS;
</PRE>

<H3>For clean up memory</H3>

This is done by the Library function <A
HREF="HTAccess.html#Library">HTLibTerminate()</A>

<PRE>
extern void HTCache_freeRoot NOPARAMS;
</PRE>

<H3>Clear a cache</H3>

Can clear a list of cache items.

<PRE>
extern void HTCacheClear PARAMS((HTList * cache));
</PRE>

<H3>To remove All cache files known to this session</H3>

<PRE>
extern void HTCacheDeleteAll NOPARAMS;

#endif
</PRE>

End of definition module
</BODY>
</HTML>

Webmaster