version 1.379, 2008/12/30 12:05:08
|
version 1.380, 2009/01/21 13:10:42
|
Line 1
|
Line 1
|
/* |
/* |
* |
* |
* (c) COPYRIGHT INRIA and W3C, 1996-2008 |
* (c) COPYRIGHT INRIA and W3C, 1996-2009 |
* Please first read the full copyright statement in file COPYRIGHT. |
* Please first read the full copyright statement in file COPYRIGHT. |
* |
* |
*/ |
*/ |
Line 16
|
Line 16
|
|
|
/* defines to include elsewhere |
/* defines to include elsewhere |
*********************************/ |
*********************************/ |
|
|
#ifdef _WINGUI |
|
#include <string.h> |
|
#endif /* !_WINGUI */ |
|
|
|
#ifdef _WX |
#ifdef _WX |
#include "wx/utils.h" |
#include "wx/utils.h" |
#include "wx/dir.h" |
#include "wx/dir.h" |
Line 30
|
Line 25
|
|
|
#define AMAYA_WWW_CACHE |
#define AMAYA_WWW_CACHE |
#define AMAYA_LOST_UPDATE |
#define AMAYA_LOST_UPDATE |
|
|
/* Amaya includes */ |
/* Amaya includes */ |
#define THOT_EXPORT extern |
#define THOT_EXPORT extern |
#include "amaya.h" |
#include "amaya.h" |
#include "init_f.h" |
#include "init_f.h" |
#include <sys/types.h> |
#include <sys/types.h> |
|
|
#ifndef _WINDOWS |
#ifndef _WINDOWS |
#include <unistd.h> |
#include <unistd.h> |
#endif /* #ifndef _WINDOWS */ |
#endif /* #ifndef _WINDOWS */ |
Line 46
|
Line 39
|
#include "HTAABrow.h" |
#include "HTAABrow.h" |
#include "string.h" |
#include "string.h" |
#include "interface.h" |
#include "interface.h" |
|
#include "message_wx.h" |
|
|
#if defined(__svr4__) || defined (_AIX) |
#if defined(__svr4__) || defined (_AIX) |
#define CATCH_SIG |
#define CATCH_SIG |
Line 54
|
Line 48
|
/* local structures coming from libwww and which are |
/* local structures coming from libwww and which are |
not found in any .h file |
not found in any .h file |
*/ |
*/ |
|
|
struct _HTStream |
struct _HTStream |
{ |
{ |
const HTStreamClass *isa; |
const HTStreamClass *isa; |
Line 276 AHTDocId_Status *GetDocIdStatus (int
|
Line 269 AHTDocId_Status *GetDocIdStatus (int
|
} |
} |
} |
} |
return (AHTDocId_Status *) NULL; |
return (AHTDocId_Status *) NULL; |
|
|
} |
} |
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
Line 1927 static void AHTAlertInit (void)
|
Line 1919 static void AHTAlertInit (void)
|
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
static void RecCleanCache (char *dirname) |
static void RecCleanCache (char *dirname) |
{ |
{ |
#ifdef _WINGUI |
char buf[MAX_LENGTH]; |
HANDLE hFindFile; |
wxString name, path; |
ThotBool status; |
wxString wx_dir_name = wxString(dirname, *wxConvCurrent); |
WIN32_FIND_DATA ffd; |
bool cont; |
char t_dir [MAX_LENGTH]; |
|
char *ptr; |
|
|
|
/* create 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); |
|
/* save the end of the dirname. We'll use it to make |
|
a complete pathname when erasing files */ |
|
ptr = &t_dir[strlen (t_dir)]; |
|
strcat (t_dir, "*"); |
|
|
|
hFindFile = FindFirstFile (t_dir, &ffd); |
/* try to delete the current directory */ |
|
if (wxRmdir(wx_dir_name)) |
if (hFindFile == INVALID_HANDLE_VALUE) |
|
/* nothing to erase? */ |
|
return; |
return; |
|
|
status = TRUE; |
/* try to delete the files & directorys inside */ |
while (status) |
wxDir wx_dir(wx_dir_name); |
{ |
cont = wx_dir.GetFirst (&name); |
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
while (cont) |
{ |
{ |
/* it's a directory, erase it recursively */ |
path = wx_dir_name+name; |
if (strcmp (ffd.cFileName, "..") && strcmp (ffd.cFileName, ".")) |
//printf ("%s\n", (const char *)path.mb_str(*wxConvCurrent)); |
{ |
// get the next name |
strcpy (ptr, ffd.cFileName); |
cont = wx_dir.GetNext (&name); |
strcat (ptr, DIR_STR); |
if (wxDirExists (path)) |
RecCleanCache (t_dir); |
{ |
rmdir (t_dir); |
/* it's a sub-directory */ |
} |
strcpy (buf, (const char *)path.mb_str(*wxConvCurrent)); |
} |
strcat (buf, DIR_STR); |
|
/* delete it recursively */ |
|
RecCleanCache(buf); |
|
} |
else |
else |
{ |
/* it's a file */ |
/* it's a file, erase it */ |
wxRemoveFile(path); |
strcpy (ptr, ffd.cFileName); |
|
TtaFileUnlink (t_dir); |
|
} |
|
status = FindNextFile (hFindFile, &ffd); |
|
} |
} |
FindClose (hFindFile); |
|
#endif /* _WINGUI */ |
|
|
|
#if defined(_WX) |
|
char buftmp[256]; |
|
|
|
#ifdef _WINDOWS |
|
wxString separator = _T("\\"); |
|
#else /* _WINDOWS */ |
|
wxString separator = _T("/"); |
|
#endif /* _WINDOWS */ |
|
|
|
wxString wx_dir_name = wxString(dirname, *wxConvCurrent); |
|
|
|
/* try to delete the current directory */ |
/* try to delete the current directory */ |
wxRmdir(wx_dir_name); |
wxRmdir(wx_dir_name); |
|
|
if (!wxDirExists(wx_dir_name)) |
|
return; |
|
|
|
/* try to delete the files & directorys inside */ |
|
{ |
|
wxDir wx_dir(wx_dir_name); |
|
wxString name; |
|
ThotBool cont = wx_dir.GetFirst(&name); |
|
while (cont) |
|
{ |
|
name = wx_dir.GetName()+separator+name; |
|
if (wxDirExists(name)) |
|
{ |
|
name = name+separator; |
|
/* it's a sub-directory */ |
|
sprintf(buftmp, "%s", (const char *)name.mb_str(*wxConvCurrent) ); |
|
/* delete it recursively */ |
|
RecCleanCache(buftmp); |
|
} |
|
else |
|
{ |
|
/* it's a file */ |
|
wxRemoveFile(name); |
|
} |
|
|
|
cont = wx_dir.GetNext(&name); |
|
} |
|
} |
|
/* try to delete the current directory */ |
|
wxRmdir(wx_dir_name); |
|
#endif /* _WX */ |
|
|
|
#ifdef _GTK |
|
DIR *dp; |
|
struct stat st; |
|
#ifdef HAVE_DIRENT_H |
|
struct dirent *d; |
|
#else /* HAVE_DIRENT_H */ |
|
struct direct *d; |
|
#endif /* HAVE_DIRENT_H */ |
|
char filename[BUFSIZ+1]; |
|
|
|
if ((dp = opendir (dirname)) == NULL) |
|
{ |
|
/* @@@ we couldn't open the directory ... we need some msg */ |
|
perror (dirname); |
|
return; |
|
} |
|
|
|
while ((d = readdir (dp)) != NULL) |
|
{ |
|
/* skip the UNIX . and .. links */ |
|
if (!strcmp (d->d_name, "..") |
|
|| !strcmp (d->d_name, ".")) |
|
continue; |
|
|
|
sprintf (filename, "%s%c%s", dirname, DIR_SEP, d->d_name); |
|
if (lstat (filename, &st) < 0 ) |
|
{ |
|
/* @@2 need some error message */ |
|
perror (filename); |
|
continue; |
|
} |
|
|
|
switch (st.st_mode & S_IFMT) |
|
{ |
|
case S_IFDIR: |
|
/* if we find a directory, we erase it, recursively */ |
|
strcat (filename, DIR_STR); |
|
RecCleanCache (filename); |
|
rmdir (filename); |
|
break; |
|
case S_IFLNK: |
|
/* skip any links we find */ |
|
continue; |
|
break; |
|
default: |
|
/* erase the filename */ |
|
TtaFileUnlink (filename); |
|
break; |
|
} |
|
} |
|
closedir (dp); |
|
#endif /* _GTK */ |
|
} |
} |
#endif /* AMAYA_WWW_CACHE */ |
#endif /* AMAYA_WWW_CACHE */ |
|
|
Line 2084 static void RecCleanCache (char *dirname
|
Line 1961 static void RecCleanCache (char *dirname
|
void libwww_CleanCache (void) |
void libwww_CleanCache (void) |
{ |
{ |
#ifdef AMAYA_WWW_CACHE |
#ifdef AMAYA_WWW_CACHE |
char * real_dir; |
char *real_dir, *cache_dir, *tmp, *ptr; |
char* cache_dir; |
|
char* tmp; |
|
int cache_size; |
int cache_size; |
int cache_expire; |
int cache_expire; |
int cache_disconnect; |
int cache_disconnect; |
ThotBool error; |
|
char * ptr; |
|
|
|
if (!HTCacheMode_enabled ()) |
if (!HTCacheMode_enabled ()) |
/* don't do anything if we're not using a cache */ |
/* don't do anything if we're not using a cache */ |
Line 2102 void libwww_CleanCache (void)
|
Line 1975 void libwww_CleanCache (void)
|
if (!tmp || *tmp == EOS) |
if (!tmp || *tmp == EOS) |
return; |
return; |
cache_dir = TtaStrdup (tmp); |
cache_dir = TtaStrdup (tmp); |
HT_FREE (tmp); |
TtaFreeMemory (tmp); |
cache_size = HTCacheMode_maxSize (); |
cache_size = HTCacheMode_maxSize (); |
cache_expire = HTCacheMode_expires (); |
cache_expire = HTCacheMode_expires (); |
cache_disconnect = HTCacheMode_disconnected (); |
cache_disconnect = HTCacheMode_disconnected (); |
Line 2111 void libwww_CleanCache (void)
|
Line 1984 void libwww_CleanCache (void)
|
tmp = HTWWWToLocal (cache_dir, "file:", NULL); |
tmp = HTWWWToLocal (cache_dir, "file:", NULL); |
real_dir = (char *)TtaGetMemory (strlen (tmp) + 20); |
real_dir = (char *)TtaGetMemory (strlen (tmp) + 20); |
strcpy (real_dir, tmp); |
strcpy (real_dir, tmp); |
HT_FREE (tmp); |
TtaFreeMemory (tmp); |
|
|
/* safeguard... abort the operation if cache_dir doesn't end with |
/* safeguard... abort the operation if cache_dir doesn't end with |
CACHE_DIR_NAME */ |
CACHE_DIR_NAME */ |
error = TRUE; |
|
ptr = strstr (real_dir, CACHE_DIR_NAME); |
ptr = strstr (real_dir, CACHE_DIR_NAME); |
if (ptr && *ptr && !strcasecmp (ptr, CACHE_DIR_NAME)) |
if (ptr == NULL || *ptr == EOS || strcasecmp (ptr, CACHE_DIR_NAME)) |
error = FALSE; |
return; |
if (error) |
|
return; |
|
|
|
/* remove the concurrent cache lock */ |
/* remove the concurrent cache lock */ |
#ifdef DEBUG_LIBWWW |
#ifdef DEBUG_LIBWWW |
Line 2131 void libwww_CleanCache (void)
|
Line 2001 void libwww_CleanCache (void)
|
HTCacheMode_setEnabled (FALSE); |
HTCacheMode_setEnabled (FALSE); |
|
|
RecCleanCache (real_dir); |
RecCleanCache (real_dir); |
|
|
HTCacheMode_setExpires ((HTExpiresMode)cache_expire); |
HTCacheMode_setExpires ((HTExpiresMode)cache_expire); |
HTCacheMode_setDisconnected ((HTDisconnectedMode)cache_disconnect); |
HTCacheMode_setDisconnected ((HTDisconnectedMode)cache_disconnect); |
HTCacheInit (cache_dir, cache_size); |
HTCacheInit (cache_dir, cache_size); |
Line 2163 static void CacheInit (void)
|
Line 2032 static void CacheInit (void)
|
{ |
{ |
#ifndef AMAYA_WWW_CACHE |
#ifndef AMAYA_WWW_CACHE |
HTCacheMode_setEnabled (NO); |
HTCacheMode_setEnabled (NO); |
|
|
#else /* AMAYA_WWW_CACHE */ |
#else /* AMAYA_WWW_CACHE */ |
char *strptr; |
char *ptr = NULL; |
char *real_dir = NULL; |
char *real_dir = NULL; |
char *cache_lockfile; |
char *cache_lockfile; |
char *cache_dir = NULL; |
char *cache_dir = NULL; |
int cache_size; |
int cache_size, i; |
int cache_entry_size; |
int cache_entry_size; |
ThotBool cache_enabled; |
ThotBool cache_enabled; |
ThotBool cache_locked; |
ThotBool cache_locked; |
ThotBool tmp_bool; |
ThotBool tmp_bool; |
|
|
int i; |
|
|
|
/* activate cache? */ |
/* activate cache? */ |
strptr = TtaGetEnvString ("ENABLE_CACHE"); |
ptr = TtaGetEnvString ("ENABLE_CACHE"); |
if (strptr && *strptr && strcasecmp (strptr, "yes")) |
if (ptr && *ptr && strcasecmp (ptr, "yes")) |
cache_enabled = NO; |
cache_enabled = NO; |
else |
else |
cache_enabled = YES; |
cache_enabled = YES; |
|
|
/* cache protected documents? */ |
/* cache protected documents? */ |
strptr = TtaGetEnvString ("CACHE_PROTECTED_DOCS"); |
ptr = TtaGetEnvString ("CACHE_PROTECTED_DOCS"); |
if (strptr && *strptr && !strcasecmp (strptr, "yes")) |
if (ptr && *ptr && !strcasecmp (ptr, "yes")) |
HTCacheMode_setProtected (YES); |
HTCacheMode_setProtected (YES); |
else |
else |
HTCacheMode_setProtected (NO); |
HTCacheMode_setProtected (NO); |
|
|
/* get the cache dir (or use a default one) */ |
/* get the cache dir (or use a default one) */ |
#ifdef _WX |
ptr = TtaGetRealFileName(TtaGetEnvString ("CACHE_DIR")); |
strptr = TtaGetRealFileName(TtaGetEnvString ("CACHE_DIR")); |
if (ptr && *ptr) |
#else /* _WX */ |
|
strptr = TtaGetEnvString ("CACHE_DIR"); |
|
#endif /* _WX */ |
|
if (strptr && *strptr) |
|
{ |
{ |
real_dir = (char *)TtaGetMemory (strlen (strptr) + strlen (CACHE_DIR_NAME) + 20); |
real_dir = (char *)TtaGetMemory (strlen (ptr) + strlen (CACHE_DIR_NAME) + 20); |
strcpy (real_dir, strptr); |
strcpy (real_dir, ptr); |
if (*(real_dir + strlen (real_dir) - 1) != DIR_SEP) |
if (*(real_dir + strlen (real_dir) - 1) != DIR_SEP) |
strcat (real_dir, DIR_STR); |
strcat (real_dir, DIR_STR); |
|
TtaFreeMemory(ptr); |
|
ptr = NULL; |
} |
} |
else |
else |
{ |
{ |
real_dir = (char *)TtaGetMemory (strlen (TempFileDirectory) + strlen (CACHE_DIR_NAME) + 20); |
real_dir = (char *)TtaGetMemory (strlen (TempFileDirectory) + strlen (CACHE_DIR_NAME) + 20); |
sprintf (real_dir, "%s%s", TempFileDirectory, CACHE_DIR_NAME); |
sprintf (real_dir, "%s%s", TempFileDirectory, CACHE_DIR_NAME); |
} |
} |
#ifdef _WX |
|
TtaFreeMemory(strptr); |
|
#endif /* _WX */ |
|
|
|
/* compatiblity with previous versions of Amaya: does real_dir |
/* compatiblity with previous versions of Amaya: does real_dir |
include CACHE_DIR_NAME? If not, add it */ |
include CACHE_DIR_NAME? If not, add it */ |
strptr = strstr (real_dir, CACHE_DIR_NAME); |
ptr = strstr (real_dir, CACHE_DIR_NAME); |
if (!strptr) |
if (!ptr) |
strcat (real_dir, CACHE_DIR_NAME); |
strcat (real_dir, CACHE_DIR_NAME); |
else |
else |
{ |
{ |
i = strlen (CACHE_DIR_NAME); |
i = strlen (CACHE_DIR_NAME); |
if (strptr[i] != EOS) |
if (ptr[i] != EOS) |
strcat (real_dir, CACHE_DIR_NAME); |
strcat (real_dir, CACHE_DIR_NAME); |
} |
} |
|
|
Line 2229 static void CacheInit (void)
|
Line 2090 static void CacheInit (void)
|
libwww */ |
libwww */ |
cache_dir = HTLocalToWWW (real_dir, "file:"); |
cache_dir = HTLocalToWWW (real_dir, "file:"); |
/* get the cache size (or use a default one) */ |
/* get the cache size (or use a default one) */ |
strptr = TtaGetEnvString ("CACHE_SIZE"); |
ptr = TtaGetEnvString ("CACHE_SIZE"); |
if (strptr && *strptr) |
if (ptr && *ptr) |
cache_size = atoi (strptr); |
cache_size = atoi (ptr); |
else |
else |
cache_size = DEFAULT_CACHE_SIZE; |
cache_size = DEFAULT_CACHE_SIZE; |
/* get the max cached file size (or use a default one) */ |
/* get the max cached file size (or use a default one) */ |
Line 2254 static void CacheInit (void)
|
Line 2115 static void CacheInit (void)
|
/* remove the lock and clean the cache (the clean cache |
/* remove the lock and clean the cache (the clean cache |
will remove all, making the following call unnecessary */ |
will remove all, making the following call unnecessary */ |
/* little trick to win some memory */ |
/* little trick to win some memory */ |
strptr = strrchr (cache_lockfile, '.'); |
ptr = strrchr (cache_lockfile, '.'); |
*strptr = EOS; |
*ptr = EOS; |
RecCleanCache (cache_lockfile); |
RecCleanCache (cache_lockfile); |
*strptr = '.'; |
*ptr = '.'; |
} |
} |
|
|
if (!cache_locked) |
if (!cache_locked) |
Line 2312 static void CacheInit (void)
|
Line 2173 static void CacheInit (void)
|
{ |
{ |
HTCacheMode_setEnabled (FALSE); |
HTCacheMode_setEnabled (FALSE); |
} |
} |
if (cache_dir) |
|
HT_FREE (cache_dir); |
TtaFreeMemory (cache_dir); |
if (real_dir) |
TtaFreeMemory (real_dir); |
TtaFreeMemory (real_dir); |
|
/* warn the user if the cache isn't active */ |
/* warn the user if the cache isn't active */ |
if (cache_enabled && !HTCacheMode_enabled ()) |
if (cache_enabled && !HTCacheMode_enabled ()) |
{ |
{ |
Line 2335 static void CacheInit (void)
|
Line 2195 static void CacheInit (void)
|
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
static void ProxyInit (void) |
static void ProxyInit (void) |
{ |
{ |
char *strptr; |
char *ptr; |
char *name; |
char *name; |
char *tmp = NULL; |
char *tmp = NULL; |
char *strptrA; |
char *ptrA; |
ThotBool proxy_is_onlyproxy; |
ThotBool proxy_is_onlyproxy; |
|
|
/* get the proxy settings from the thot.ini file */ |
/* get the proxy settings from the thot.ini file */ |
strptr = TtaGetEnvString ("HTTP_PROXY"); |
ptr = TtaGetEnvString ("HTTP_PROXY"); |
if (strptr && *strptr) |
if (ptr && *ptr) |
{ |
{ |
tmp = (char *) TtaGetMemory (strlen (strptr) + 1); |
tmp = (char *) TtaGetMemory (strlen (ptr) + 1); |
strcpy (tmp, strptr); |
strcpy (tmp, ptr); |
|
|
/* does the proxy env string has an "http://" prefix? */ |
/* does the proxy env string has an "http://" prefix? */ |
if (!strncasecmp (strptr, "http://", 7)) |
if (!strncasecmp (ptr, "http://", 7)) |
HTProxy_add ("http", tmp); |
HTProxy_add ("http", tmp); |
else |
else |
{ |
{ |
strptrA = (char *) TtaGetMemory (strlen (strptr) + 9); |
ptrA = (char *) TtaGetMemory (strlen (ptr) + 9); |
strcpy (strptrA, "http://"); |
strcpy (ptrA, "http://"); |
strcat (strptrA, tmp); |
strcat (ptrA, tmp); |
HTProxy_add ("http", strptrA); |
HTProxy_add ("http", ptrA); |
TtaFreeMemory (strptrA); |
TtaFreeMemory (ptrA); |
} |
} |
TtaFreeMemory (tmp); |
TtaFreeMemory (tmp); |
} |
} |
|
|
/* get the no_proxy settings from the thot.ini file */ |
/* get the no_proxy settings from the thot.ini file */ |
strptr = TtaGetEnvString ("PROXYDOMAIN"); |
ptr = TtaGetEnvString ("PROXYDOMAIN"); |
if (strptr && *strptr) |
if (ptr && *ptr) |
{ |
{ |
strptrA = (char *) TtaGetMemory (strlen (strptr) + 1); |
ptrA = (char *) TtaGetMemory (strlen (ptr) + 1); |
tmp = strptrA; |
tmp = ptrA; |
strcpy (tmp, strptr); |
strcpy (tmp, ptr); |
/* as HTNextField changes the ptr we pass as an argument, we'll |
/* as HTNextField changes the ptr we pass as an argument, we'll |
work with another variable, so that we can free the tmp |
work with another variable, so that we can free the tmp |
block later on */ |
block later on */ |
Line 2385 static void ProxyInit (void)
|
Line 2245 static void ProxyInit (void)
|
/* Register it for all access methods */ |
/* Register it for all access methods */ |
HTNoProxy_add (name, NULL, port); |
HTNoProxy_add (name, NULL, port); |
} |
} |
TtaFreeMemory (strptrA); |
TtaFreeMemory (ptrA); |
} |
} |
|
|
/* how should we interpret the proxy domain list? */ |
/* how should we interpret the proxy domain list? */ |
Line 2403 static void ProxyInit (void)
|
Line 2263 static void ProxyInit (void)
|
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
static void AHTProfile_newAmaya (const char *AppName, const char *AppVersion) |
static void AHTProfile_newAmaya (const char *AppName, const char *AppVersion) |
{ |
{ |
char *strptr; |
char *ptr; |
|
|
/* If the Library is not already initialized then do it */ |
/* If the Library is not already initialized then do it */ |
if (!HTLib_isInitialized ()) |
if (!HTLib_isInitialized ()) |
Line 2446 static void AHTProfile_newAmaya (const c
|
Line 2306 static void AHTProfile_newAmaya (const c
|
/* Set up the default set of Authentication schemes */ |
/* Set up the default set of Authentication schemes */ |
HTAA_newModule ("basic", HTBasic_generate, HTBasic_parse, NULL, HTBasic_delete); |
HTAA_newModule ("basic", HTBasic_generate, HTBasic_parse, NULL, HTBasic_delete); |
/* activate MDA by defaul */ |
/* activate MDA by defaul */ |
strptr = TtaGetEnvString ("ENABLE_MDA"); |
ptr = TtaGetEnvString ("ENABLE_MDA"); |
if (!strptr || (strptr && *strptr && strcasecmp (strptr, "no"))) |
if (!ptr || (ptr && *ptr && strcasecmp (ptr, "no"))) |
HTAA_newModule ("digest", HTDigest_generate, HTDigest_parse, HTDigest_updateInfo, HTDigest_delete); |
HTAA_newModule ("digest", HTDigest_generate, HTDigest_parse, HTDigest_updateInfo, HTDigest_delete); |
|
|
/* Get any proxy settings */ |
/* Get any proxy settings */ |
Line 2506 static void AHTProfile_delete (v
|
Line 2366 static void AHTProfile_delete (v
|
HTList_delete (Amaya->reqlist); |
HTList_delete (Amaya->reqlist); |
TtaFreeMemory (Amaya); |
TtaFreeMemory (Amaya); |
|
|
#ifdef _WINGUI |
|
if (HTLib_isInitialized ()) |
|
HTEventTerminate (); |
|
#endif /* _WINGUI; */ |
|
|
|
/* Clean up the persistent cache (if any) */ |
/* Clean up the persistent cache (if any) */ |
#ifdef AMAYA_WWW_CACHE |
#ifdef AMAYA_WWW_CACHE |
clear_cachelock (); |
clear_cachelock (); |
Line 2556 static void AmayaContextInit ()
|
Line 2411 static void AmayaContextInit ()
|
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
void QueryInit () |
void QueryInit () |
{ |
{ |
char *strptr; |
char *ptr; |
int tmp_i; |
int tmp_i; |
long tmp_l; |
long tmp_l; |
|
|
Line 2564 void QueryInit ()
|
Line 2419 void QueryInit ()
|
AHTProfile_newAmaya (TtaGetAppName(), TtaGetAppVersion()); |
AHTProfile_newAmaya (TtaGetAppName(), TtaGetAppVersion()); |
CanDoStop_set (TRUE); |
CanDoStop_set (TRUE); |
UserAborted_flag = FALSE; |
UserAborted_flag = FALSE; |
|
|
#ifdef _WINGUI |
|
HTEventInit (); |
|
#endif /* _WINGUI */ |
|
|
|
#ifdef _WX |
#ifdef _WX |
wxAmayaSocketEventLoop::InitSocketLib(); |
wxAmayaSocketEventLoop::InitSocketLib(); |
#endif /* _WX */ |
|
|
|
#if defined(_GTK) || defined(_WX) |
|
HTEvent_setRegisterCallback ( AHTEvent_register); |
HTEvent_setRegisterCallback ( AHTEvent_register); |
HTEvent_setUnregisterCallback (AHTEvent_unregister); |
HTEvent_setUnregisterCallback (AHTEvent_unregister); |
HTTimer_registerSetTimerCallback ((BOOL (*)(HTTimer*)) AMAYA_SetTimer); |
HTTimer_registerSetTimerCallback ((BOOL (*)(HTTimer*)) AMAYA_SetTimer); |
HTTimer_registerDeleteTimerCallback ((BOOL (*)(HTTimer*))AMAYA_DeleteTimer); |
HTTimer_registerDeleteTimerCallback ((BOOL (*)(HTTimer*))AMAYA_DeleteTimer); |
#endif /* defined(_GTK) || defined(_WX) */ |
#endif /* _WX */ |
|
|
#ifdef HTDEBUG |
#ifdef HTDEBUG |
/* an undocumented option for being able to generate an HTTP protocol |
/* an undocumented option for being able to generate an HTTP protocol |
trace. The flag can take values from 1-10, which are interpreted as |
trace. The flag can take values from 1-10, which are interpreted as |
Line 2662 void QueryInit ()
|
Line 2508 void QueryInit ()
|
/* Setting up different network parameters */ |
/* Setting up different network parameters */ |
|
|
/* Maximum number of simultaneous open sockets */ |
/* Maximum number of simultaneous open sockets */ |
strptr = TtaGetEnvString ("MAX_SOCKET"); |
ptr = TtaGetEnvString ("MAX_SOCKET"); |
if (strptr && *strptr) |
if (ptr && *ptr) |
tmp_i = atoi (strptr); |
tmp_i = atoi (ptr); |
else |
else |
tmp_i = DEFAULT_MAX_SOCKET; |
tmp_i = DEFAULT_MAX_SOCKET; |
HTNet_setMaxSocket (tmp_i); |
HTNet_setMaxSocket (tmp_i); |
|
|
/* different network services timeouts */ |
/* different network services timeouts */ |
/* dns timeout */ |
/* dns timeout */ |
strptr = TtaGetEnvString ("DNS_TIMEOUT"); |
ptr = TtaGetEnvString ("DNS_TIMEOUT"); |
if (strptr && *strptr) |
if (ptr && *ptr) |
tmp_i = atoi (strptr); |
tmp_i = atoi (ptr); |
else |
else |
tmp_i = DEFAULT_DNS_TIMEOUT; |
tmp_i = DEFAULT_DNS_TIMEOUT; |
HTDNS_setTimeout (tmp_i); |
HTDNS_setTimeout (tmp_i); |
|
|
/* persistent connections timeout */ |
/* persistent connections timeout */ |
strptr = TtaGetEnvString ("PERSIST_CX_TIMEOUT"); |
ptr = TtaGetEnvString ("PERSIST_CX_TIMEOUT"); |
if (strptr && *strptr) |
if (ptr && *ptr) |
tmp_l = atol (strptr); |
tmp_l = atol (ptr); |
else |
else |
tmp_l = DEFAULT_PERSIST_TIMEOUT; |
tmp_l = DEFAULT_PERSIST_TIMEOUT; |
HTHost_setPersistTimeout (tmp_l); |
HTHost_setPersistTimeout (tmp_l); |
|
|
/* default timeout in ms */ |
/* default timeout in ms */ |
strptr = TtaGetEnvString ("NET_EVENT_TIMEOUT"); |
ptr = TtaGetEnvString ("NET_EVENT_TIMEOUT"); |
if (strptr && *strptr) |
if (ptr && *ptr) |
tmp_i = atoi (strptr); |
tmp_i = atoi (ptr); |
else |
else |
tmp_i = DEFAULT_NET_EVENT_TIMEOUT; |
tmp_i = DEFAULT_NET_EVENT_TIMEOUT; |
HTHost_setEventTimeout (tmp_i); |
HTHost_setEventTimeout (tmp_i); |
Line 3864 ThotBool AHTFTPURL_flag (void)
|
Line 3710 ThotBool AHTFTPURL_flag (void)
|
return (FTPURL_flag); |
return (FTPURL_flag); |
} |
} |
|
|
|
|
/*---------------------------------------------------------------------- |
|
CheckSingleInstance |
|
Returns TRUE if this is the single instance of Amaya in the system, |
|
FALSE otherwise. |
|
N.B. : This implementation is naif. |
|
----------------------------------------------------------------------*/ |
|
ThotBool CheckSingleInstance (char *pid_dir) |
|
{ |
|
#ifdef _WINGUI |
|
HWND hwnd; |
|
|
|
hwnd = FindWindow ("Amaya", NULL); |
|
|
|
if (!hwnd) |
|
return TRUE; |
|
else |
|
return FALSE; |
|
|
|
#endif /* _WINGUI */ |
|
|
|
#ifdef _WX |
|
/* TODO */ |
|
return TRUE; |
|
#endif /* _WX */ |
|
|
|
#ifdef _GTK |
|
int instances; |
|
char *ptr; |
|
pid_t pid; |
|
|
|
DIR *dp; |
|
struct stat st; |
|
#ifdef HAVE_DIRENT_H |
|
struct dirent *d; |
|
#else |
|
struct direct *d; |
|
#endif /* HAVE_DIRENT_H */ |
|
char filename[BUFSIZ+1]; |
|
|
|
if ((dp = opendir (pid_dir)) == NULL) |
|
{ |
|
/* @@@ we couldn't open the directory ... we need some msg */ |
|
perror (pid_dir); |
|
return FALSE; |
|
} |
|
|
|
instances = 0; |
|
|
|
while ((d = readdir (dp)) != NULL) |
|
{ |
|
/* skip the UNIX . and .. links */ |
|
if (!strcmp (d->d_name, "..") |
|
|| !strcmp (d->d_name, ".")) |
|
continue; |
|
|
|
sprintf (filename, "%s%c%s", pid_dir, DIR_SEP, d->d_name); |
|
if (lstat (filename, &st) < 0 ) |
|
{ |
|
/* @@2 need some error message */ |
|
perror (filename); |
|
continue; |
|
} |
|
|
|
switch (st.st_mode & S_IFMT) |
|
{ |
|
case S_IFDIR: |
|
case S_IFLNK: |
|
/* skip any links and directories that we find */ |
|
continue; |
|
break; |
|
default: |
|
/* check if this pid exists. If not, erase it */ |
|
ptr = strrchr (filename, DIR_SEP); |
|
if (!ptr) |
|
continue; |
|
sscanf (ptr, DIR_STR"%d", &pid); |
|
if (kill (pid, 0) == -1) |
|
{ |
|
/* erase the stale pid file */ |
|
TtaFileUnlink (filename); |
|
} |
|
else /* we found one live instance */ |
|
{ |
|
instances++; |
|
} |
|
break; |
|
} |
|
} |
|
closedir (dp); |
|
return (instances == 0); |
|
#endif /* _GTK */ |
|
|
|
} |
|
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
FreeAmayaCache |
FreeAmayaCache |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
void FreeAmayaCache (void) |
void FreeAmayaCache (void) |
{ |
{ |
#if defined(_UNIX) |
#ifdef _UNIX |
char str[MAX_LENGTH]; |
char str[MAX_LENGTH]; |
pid_t pid; |
pid_t pid; |
|
|
Line 3973 void FreeAmayaCache (void)
|
Line 3724 void FreeAmayaCache (void)
|
sprintf (str, "%s/pid/%d", TempFileDirectory, pid); |
sprintf (str, "%s/pid/%d", TempFileDirectory, pid); |
if (TtaFileExist (str)) |
if (TtaFileExist (str)) |
TtaFileUnlink (str); |
TtaFileUnlink (str); |
#endif /* #if defined(_UNIX) */ |
#endif /* _UNIX */ |
} |
} |
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
Line 4022 void InitAmayaCache (void)
|
Line 3773 void InitAmayaCache (void)
|
#endif /* _UNIX */ |
#endif /* _UNIX */ |
|
|
/* Detect if it's a unique instance */ |
/* Detect if it's a unique instance */ |
AmayaUniqueInstance = CheckSingleInstance (str); |
AmayaUniqueInstance = TRUE; |
if (can_erase && AmayaUniqueInstance) |
if (can_erase && AmayaUniqueInstance) |
{ |
{ |
/* Erase the previous directories */ |
/* Erase the previous directories */ |