[0001]
[0002]
[0003]
[0004]
[0005]
[0006]
[0007]
[0008]
[0009]
[0010]
[0011]
[0012]
[0013]
[0014]
[0015]
[0016]
[0017]
[0018]
[0019]
[0020]
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
[0027]
[0028]
[0029]
[0030]
[0031]
[0032]
[0033]
[0034]
[0035]
[0036]
[0037]
[0038]
[0039]
[0040]
[0041]
[0042]
[0043]
[0044]
[0045]
[0046]
[0047]
[0048]
[0049]
[0050]
[0051]
[0052]
[0053]
[0054]
[0055]
[0056]
[0057]
[0058]
[0059]
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071]
[0072]
[0073]
[0074]
[0075]
[0076]
[0077]
[0078]
[0079]
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105]
[0106]
[0107]
[0108]
[0109]
[0110]
[0111]
[0112]
[0113]
[0114]
[0115]
[0116]
[0117]
[0118]
[0119]
[0120]
[0121]
[0122]
[0123]
[0124]
[0125]
[0126]
[0127]
[0128]
[0129]
[0130]
[0131]
[0132]
[0133]
[0134]
[0135]
[0136]
[0137]
[0138]
[0139]
[0140]
[0141]
[0142]
[0143]
[0144]
[0145]
[0146]
[0147]
[0148]
[0149]
[0150]
[0151]
[0152]
[0153]
[0154]
[0155]
[0156]
[0157]
[0158]
[0159]
/*****************************************************************************/
/*
                                  cache.h
*/
/*****************************************************************************/

#ifndef CACHE_H_LOADED
#define CACHE_H_LOADED 1

#include "wasd.h"
#include "file.h"

/* number of bytes in each chunk of cache memory */
#define CACHE_CHUNK_SIZE 256
#define CACHE_CONTENT_TYPE_SIZE 64

#define CACHE_EXPIRES_NONE   0xffffffff
#define CACHE_EXPIRES_DAY    0xfffffffe
#define CACHE_EXPIRES_HOUR   0xfffffffd
#define CACHE_EXPIRES_MINUTE 0xfffffffc
/* any other value will be considered literal seconds */

/**************/
/* structures */
/**************/

#pragma member_alignment __save
#pragma member_alignment

typedef struct CacheStruct FILE_CENTRY;

struct CacheStruct
{
   LIST_ENTRY  CacheListEntry;

   struct CacheStruct  *HashCollisionNextPtr,
                       *HashCollisionPrevPtr;

   BOOL  /* cache data is currently being loaded */
         DataLoading,
         /* is a permanent entry */
         EntryPermanent,
         /* cache entry has been invalidated to reclaim memory */
         EntryReclaimed,
         /* cache data is currently being revalidated */
         EntryRevalidating,
         /* data in cache is valid and can be use for requests */
         EntryValid,
         /* loaded via FILE module */
         FromFile,
         /* loaded via NET module */
         FromNet,
         /* loaded via CGI module */
         FromScript,
         /* remove allocated data buffer as soon as not in use */
         Purge,
         /* also remove cache entry */
         PurgeCompletely;

   int  /* some portion of the CGI header is contained in the cache */
        CgiHeaderLength,
        /* analogue to 'rqPathSet.CacheExpiresAfter' */
        ExpiresAfterPeriod,
        /* expires on the change of day, hour or minute */
        ExpiresAfterTime,
        /* server-tick second when the content expires */
        ExpiresTickSecond,
        /* server-tick second where it is still considered recent */
        FrequentTickSecond,
        /* the last guard period set against this entry */
        GuardSeconds,
        /* server-tick second when gaurd period expires */
        GuardTickSecond;

   unsigned short  /* file protection bitmap */
                   Protection,
                   /* file ownership UIC group number */
                   UicGroup,
                   /* file ownership UIC member number */
                   UicMember;

   unsigned long  /* length of data (file contents) at 'ContentPtr' */
                  ContentLength,
                  /* virtual block number of end-of-file */
                  EndOfFileVbn,
                  /* size of the block pointed to by 'ContentPtr' */
                  EntrySize,
                  /* first free byte in end-of-file VBN */
                  FirstFreeByte,
                  /* length of GZIP deflated data at 'GzipContentPtr' */
                  GzipContentLength,
                  /* size of the block pointed to by 'ContentPtr' */
                  GzipEntrySize,
                  /* number of times cache used */
                  HitCount,
                  /* number of times cache hit but file unmodified */
                  HitNotModifiedCount,
                  /* cache entry is in use and should not be modified */
                  InUseCount,
                  /* seconds time when last loaded */
                  LoadSeconds,
                  /* number of times the entry has been validated */
                  ValidatedCount;

   int64  /* creation quadword */
          CdtTime64,
          /* last hit quadword */
          HitTime64,
          /* when cache data loaded quadword */
          LoadTime64,
          /* last modified quadword */
          RdtTime64,
          /* last validated quadword */
          ValidateTime64;

   char  /* points to entry contents */
         *ContentPtr,
         /* points to the GZIP deflated content */
         *GzipContentPtr;

   char  /* HTTP/1.1 entity tag */
         EntityTag [CACHE_ENTITY_MAX+1],
         /* entry's MIME content type */
         ContentType [CACHE_CONTENT_TYPE_SIZE];

   /* MD5 hash of cached resource (can be path, can be file name) */
   MD5_HASH  Md5Hash;

   ODS_STRUCT  FileOds;

   /* used to buffer the function address of the content handler */
   REQUEST_AST  ContentHandlerFunction;
};

#pragma member_alignment __restore

/***********************/
/* function prototypes */
/***********************/

void CacheAcpInfoAst (REQUEST_STRUCT*);
int CacheBegin (REQUEST_STRUCT*);
void CacheEnd (REQUEST_STRUCT*);
void CacheInit ();
BOOL CacheLoadBegin (REQUEST_STRUCT*, int, char*);
int CacheLoadData (REQUEST_STRUCT*, char*, int);
BOOL CacheLoadResponse (REQUEST_STRUCT*);
void CacheLoadEnd (REQUEST_STRUCT*);
int CacheSearch (REQUEST_STRUCT*);
void CacheNext (REQUEST_STRUCT*);
void CachePurge (BOOL, int*, int*);
void CacheRemoveEntry (FILE_CENTRY*, BOOL);
void CacheReport (REQUEST_STRUCT*, BOOL);
void CacheReportEntry (REQUEST_STRUCT*, char*);
void CacheZeroCounters ();

#endif /* CACHE_H_LOADED */

/*****************************************************************************/