version 1.127, 1998/09/04 09:14:36
|
version 1.128, 1998/09/09 13:59:19
|
Line 23
|
Line 23
|
#define AMAYA_WWW_CACHE |
#define AMAYA_WWW_CACHE |
#endif /* !_WINDOWS */ |
#endif /* !_WINDOWS */ |
|
|
/*** for windows? ***/ |
#define CACHE_DIR_NAME DIR_STR"libwww-cache" |
|
|
#ifndef _WINDOWS |
|
#define CACHE_DIR_NAME "/libwww-cache" |
|
#else |
|
#define CACHE_DIR_NAME "\\libwww-cache" |
|
#endif /* !_WINDOWS */ |
|
|
|
|
|
|
|
#define DEFAULT_CACHE_SIZE 5 |
#define DEFAULT_CACHE_SIZE 5 |
|
|
|
|
/* Amaya includes */ |
/* Amaya includes */ |
#define THOT_EXPORT extern |
#define THOT_EXPORT extern |
#include "amaya.h" |
#include "amaya.h" |
Line 86 static HTList *encodings = NULL;
|
Line 76 static HTList *encodings = NULL;
|
static int object_counter = 0; /* loaded objects counter */ |
static int object_counter = 0; /* loaded objects counter */ |
static boolean AmayaAlive; /* set to 1 if the application is active; |
static boolean AmayaAlive; /* set to 1 if the application is active; |
0 if we have killed */ |
0 if we have killed */ |
|
#ifdef AMAYA_WWW_CACHE |
|
static int cache_size = 0; /* size of the cache in megabytes */ |
|
#endif /* WWW_AMAYACACHE */ |
|
|
#include "answer_f.h" |
#include "answer_f.h" |
#include "query_f.h" |
#include "query_f.h" |
Line 97 static boolean AmayaAlive; /* set t
|
Line 90 static boolean AmayaAlive; /* set t
|
/* prototypes */ |
/* prototypes */ |
|
|
#ifdef __STDC__ |
#ifdef __STDC__ |
|
static void RecCleanCache (char *dirname); |
#ifdef _WINDOWS |
#ifdef _WINDOWS |
int WIN_Activate_Request (HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar*); |
int WIN_Activate_Request (HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar*); |
#endif /* _WINDOWS */ |
#endif /* _WINDOWS */ |
#else |
#else |
|
static void RecCleanCache (/* char *dirname */); |
#ifdef _WINDOWS |
#ifdef _WINDOWS |
int WIN_Activate_Request (); |
int WIN_Activate_Request (/* HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar* */); |
#endif /* _WINDOWS */ |
#endif /* _WINDOWS */ |
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
|
|
Line 1094 static void AHTAlertInit ()
|
Line 1089 static void AHTAlertInit ()
|
#endif /* AMAYA_WWW_CACHE */ |
#endif /* AMAYA_WWW_CACHE */ |
} |
} |
|
|
#ifndef _WINDOWS |
/*---------------------------------------------------------------------- |
/* @@@ needs specific win functions */ |
libwww_CleanCache |
|
frontend to the recursive cache cleaning function |
|
----------------------------------------------------------------------*/ |
|
#ifdef __STDC__ |
|
void libwww_CleanCache (void) |
|
#else |
|
void libwww_CleanCache () |
|
Document doc; |
|
View view; |
|
#endif /* __STDC__ */ |
|
{ |
|
char *strptr; |
|
char *cache_dir; |
|
int cache_size; |
|
#ifdef AMAYA_WWW_CACHE |
|
if (!HTCacheMode_enabled ()) |
|
/* don't do anything if we're not using a cache */ |
|
return; |
|
/* temporarily close down the cache, purge it, then restart */ |
|
cache_dir = strdup (HTCacheMode_getRoot ()); |
|
cache_size = HTCacheMode_maxSize (); |
|
HTCacheTerminate (); |
|
strptr = TtaGetMemory (strlen (cache_dir) + 2); |
|
strcpy (strptr, cache_dir); |
|
strcat (strptr, DIR_STR); |
|
|
|
RecCleanCache (strptr); |
|
|
|
TtaFreeMemory (strptr); |
|
HTCacheMode_setExpires(HT_EXPIRES_AUTO); |
|
HTCacheInit (cache_dir, cache_size); |
|
TtaFreeMemory (cache_dir); |
|
#endif /* AMAYA_WWW_CACHE */ |
|
} |
|
|
#ifdef AMAYA_WWW_CACHE |
#ifdef AMAYA_WWW_CACHE |
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
CleanCache |
RecCleanCache |
Clears an existing cache directory |
Clears an existing cache directory |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
#ifdef __STDC__ |
#ifdef __STDC__ |
void CleanCache (char *dirname) |
static void RecCleanCache (char *dirname) |
#else |
#else |
void CleanCache (dirname) |
static void RecCleanCache (char *dirname) |
char *dirname; |
Document doc; |
|
View view; |
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
|
|
|
#ifdef _WINDOWS |
|
{ |
|
HANDLE hFindFile; |
|
boolean status; |
|
WIN32_FIND_DATA ffd; |
|
|
|
char t_dir [MAX_LENGTH]; |
|
|
|
/* creat a t_dir name to start searching for files */ |
|
if ((strlen (dirname) + 10) > MAX_LENGTH) |
|
/* ERROR: directory name is too big */ |
|
return; |
|
|
|
strcpy (t_dir, dirname); |
|
strcat (t_dir, "\\*"); |
|
|
|
hFindFile = FindFirstFile ("t_dir", &ffd); |
|
|
|
if (hFindFile == INVALID_HANDLE_VALUE) |
|
/* nothing to erase? */ |
|
return; |
|
|
|
status = TRUE; |
|
while (status) { |
|
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
|
{ |
|
/* it's a directory, erase it recursively */ |
|
RecCleanCache (ffd.cFileName); |
|
rmdir (ffd.cFileName); |
|
} |
|
else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) |
|
{ |
|
/* it's a file, erase it */ |
|
/*TtaUnlink (ffd.cFileName); */ |
|
/* @@ false condition, for not doing anything */ |
|
status = TRUE; |
|
} |
|
status = FindNextFile (hFindFile, &ffd); |
|
} |
|
FindClose (hFindFile); |
|
} |
|
|
|
#else /* _WINDOWS */ |
{ |
{ |
DIR *dp; |
DIR *dp; |
struct stat st; |
struct stat st; |
Line 1115 char *dirname;
|
Line 1189 char *dirname;
|
#else |
#else |
struct direct *d; |
struct direct *d; |
#endif /* HAVE_DIRENT_H */ |
#endif /* HAVE_DIRENT_H */ |
char filename [BUFSIZ+1]; |
char filename[BUFSIZ+1]; |
|
|
if ((dp = opendir (dirname)) == NULL) |
if ((dp = opendir (dirname)) == NULL) |
{ |
{ |
Line 1126 char *dirname;
|
Line 1200 char *dirname;
|
|
|
while ((d = readdir (dp)) != NULL) |
while ((d = readdir (dp)) != NULL) |
{ |
{ |
#ifndef _WINDOWS |
|
/* skip the UNIX . and .. links */ |
/* skip the UNIX . and .. links */ |
if (!strcmp (d->d_name, "..") |
if (!strcmp (d->d_name, "..") |
|| !strcmp (d->d_name, ".")) |
|| !strcmp (d->d_name, ".")) |
continue; |
continue; |
#endif _WINDOWS |
|
|
|
sprintf (filename, "%s%s", dirname, d->d_name); |
sprintf (filename, "%s"DIR_STR"%s", dirname, d->d_name); |
if (lstat (filename, &st) < 0 ) |
if (lstat (filename, &st) < 0 ) |
{ |
{ |
/* @@2 need some error message */ |
/* @@2 need some error message */ |
Line 1145 char *dirname;
|
Line 1217 char *dirname;
|
{ |
{ |
case S_IFDIR: |
case S_IFDIR: |
/* if we find a directory, we erase it, recursively */ |
/* if we find a directory, we erase it, recursively */ |
strcat (filename, "/"); |
strcat (filename, DIR_STR); |
CleanCache (filename); |
RecCleanCache (filename); |
|
rmdir (filename); |
break; |
break; |
case S_IFLNK: |
case S_IFLNK: |
/* skip any links we find */ |
/* skip any links we find */ |
Line 1159 char *dirname;
|
Line 1232 char *dirname;
|
} |
} |
} |
} |
closedir (dp); |
closedir (dp); |
/* erase the directory */ |
|
rmdir (dirname); |
|
} |
} |
|
#endif /* _WINDOWS */ |
#endif /* AMAYA_WWW_CACHE */ |
#endif /* AMAYA_WWW_CACHE */ |
#endif /* !_WINDOWS */ |
|
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
CacheInit |
CacheInit |
Line 1181 static void Cacheinit ()
|
Line 1252 static void Cacheinit ()
|
|
|
#else /* AMAYA_WWW_CACHE */ |
#else /* AMAYA_WWW_CACHE */ |
char *strptr; |
char *strptr; |
int cache_size; |
|
char *cache_dir = NULL; |
char *cache_dir = NULL; |
boolean cache; |
boolean cache; |
|
|
/* activate cache? */ |
/* activate cache? */ |
strptr = (char *) TtaGetEnvString ("ENABLE_CACHE"); |
strptr = (char *) TtaGetEnvString ("ENABLE_CACHE"); |
if (strptr && *strptr && strcasecmp (strptr,"yes" )) |
if (strptr && *strptr && strcasecmp (strptr,"yes" )) |
Line 1222 static void Cacheinit ()
|
Line 1292 static void Cacheinit ()
|
the directory, etc. attention to dir-sep */ |
the directory, etc. attention to dir-sep */ |
strptr = TtaGetMemory (strlen (cache_dir) + 20); |
strptr = TtaGetMemory (strlen (cache_dir) + 20); |
strcpy (strptr, cache_dir); |
strcpy (strptr, cache_dir); |
#ifndef _WINDOWS |
strcat (strptr, DIR_STR".lock"); |
strcat (strptr, "/.lock"); |
|
#else |
|
strcat (strptr, "\\.lock"); |
|
#endif /* !_WINDOWS */ |
|
if (TtaFileExist (strptr)) |
if (TtaFileExist (strptr)) |
{ |
{ |
/* remove the lock and clean the cache (the clean cache will remove |
/* remove the lock and clean the cache (the clean cache will remove |
all, making the following call unnecessary */ |
all, making the following call unnecessary */ |
strcpy (strptr, cache_dir); |
strcpy (strptr, cache_dir); |
/* @@@ add DIRSEP */ |
strcat (strptr, DIR_STR); |
strcat (strptr, "/"); |
RecCleanCache (strptr); |
#ifndef _WINDOWS |
|
CleanCache (strptr); |
|
#endif /* !_WINDOWS */ |
|
} |
} |
TtaFreeMemory (strptr); |
TtaFreeMemory (strptr); |
|
|