The cache_digest function calculates the MD5 signature of a specified URL and stores the signature in a digest variable.
#include <libproxy/cache.h> void cache_digest(char *url, unsigned char digest[16]));
void
char *url is a string containing the cache file name of a URL.
name *digest is an array to store the MD5 signature of the URL.
The cache_filename function returns the cache file name for a given URL, specified by the MD5 signature.
Syntax
#include <libproxy/cutil.h> char *cache_filename(unsigned char digest[16]);
Returns
A new string containing the cache filename.
Parameters
char *digest is an array containing the MD5 signature of a URL.
The cache_fn_to_dig function converts a cache file name of a URL into a partial MD5 digest.
#include <libproxy/cutil.h> void *cache_fn_to_dig(char *name, unsigned char digest[16]));
void
char *name is a string containing the cache file name of a URL.
name *digest is an array to receive first 8 bits of the signature of the URL.
The CALLOC macro is a platform-independent substitute for the C library routine calloc. It allocates num*size bytes from the request’s memory pool. If pooled memory has been disabled in the configuration file with the pool-init built-in SAF, PERM_CALLOC and CALLOC both obtain their memory from the system heap.
void *CALLOC(int size)
A void pointer to a block of memory.
int size is the size in bytes of each element.
char *name;name = (char *) CALLOC(100);
FREE, REALLOC, STRDUP, PERM_MALLOC, PERM_FREE, PERM_REALLOC, PERM_STRDUP
The ce_free function releases memory allocated by the ce_lookup function.
#include <libproxy/cache.h> void cd_free(CacheEntry *ce);
void
CacheEntry *ce is a cache entry structure to be destroyed.
The ce_lookup cache entry lookup function looks up a cache entry for a specified URL.
#include <libproxy/cache.h> CacheEntry *ce_lookup(Session *sn, Request *rq, char *url, time_t ims_c);
NULL if caching is not enabled
A newly allocated CacheEntry structure, whether or not a copy existed in the cache. Within that structure, the ce->state field reports about the existence:
CACHE_NO signals that the document is not and will not be cached. Other fields in the cache structure may be NULL
CACHE_CREATE signals that the cache file doesn’t exist but may be created once the remote server is contacted. However, during the retrieval it may turn out that the document not be cacheable.
CACHE_REFRESH signals that the cache file exists but must be refreshed before being used. The data might still be up to date but the remote server needs to be contacted to find out. If the file is not up to date, the cache file will be replaced with the new document version sent by the remote origin server.
CACHE_RETURN_FROM_CACHE signals that the cache file exists and is up-to-date based on the configuration and current parameters controlling what is considered fresh.
CACHE_RETURN_ERROR is a signal that happens only if the proxy is set to no-network mode connect-Modenese, and the document does not exist in the cache.
Session *sn identifies the Session structure.
Request *rq identifies the Request structure.
char *url contains the name of the URL for which the cache is being sought.
time-out misc. is the if-modified-since time.
The cif_write_entry function writes a CIF entry for a specified CacheEntry structure. The CIF entry is stored in the cache file itself.
#include <libproxy/cif.h> int cif_write_entry(CacheEntry *ce,int new_cachefile)
nonzero if the write was successful
0 if the write was unsuccessful
CacheEntry *ce is a cache entry structure to be written to the .cif file.
int new_cachefile The values are 1 or 0:
1 if the file is a new cache file
0 if the file exists and the CIF entry is to be modified
The cinfo_find() function uses the MIME types information to find the type, encoding, and/or language based on the extensions of the Universal Resource Identifier (URI) or local file name. Use this information to send headers (rq->srvhdrs) to the client indicating the content-type, content-encoding, and content-language of the data that the client will be receiving from the server.
The name used consists of all of the text after the last slash (/) or the whole string if no slash is found. File name extensions are not case-sensitive. The name may contain multiple extensions separated by period (.) to indicate type, encoding, or language. For example, the URI a/b/filename.jp.txt.zip could represent a Japanese language, text/plain type, .zip-encoded file.
cinfo *cinfo_find(char *uri);
A pointer to a newly allocated cinfo structure if content info was found, or NULL if no content was found.
The cinfo structure that is allocated and returned contains pointers to the content-type, content-encoding, and content-language, if found. Each is a pointer into static data in the types database, or NULL if not found. Do not free these pointers. You should free the cinfo structure when you are done using it.
char *uri is a Universal Resource Identifier (URI) or local file name. Multiple file name extensions should be separated by periods (.).
The condvar_init function is a critical-section function that initializes and returns a new condition variable associated with a specified critical-section variable. You can use the condition variable to prevent interference between two threads of execution.
CONDVAR condvar_init(CRITICAL id);
A newly allocated condition variable (CONDVAR).
CRITICAL id is a critical-section variable.
condvar_notify, condvar_terminate, condvar_wait, crit_init, crit_enter, crit_exit, crit_terminate
The condvar_notify function is a critical-section function that awakens any threads that are blocked on the given critical-section variable. Use this function to awaken threads of execution of a given critical section. First, use crit_enter to gain ownership of the critical section. Then use the returned critical-section variable to call condvar_notify to awaken the threads. Finally, when condvar_notify returns, call crit_exit to surrender ownership of the critical section.
void condvar_notify(CONDVAR cv);
void
CONDVAR cv is a condition variable.
condvar_init, condvar_terminate, condvar_wait, crit_init, crit_enter, crit_exit, crit_terminate
The condvar_terminate function is a critical-section function that frees a condition variable. Use this function to free a previously allocated condition variable.
Terminating a condition variable that is in use can lead to unpredictable results.
void condvar_terminate(CONDVAR cv);
void
CONDVAR cv is a condition variable.
condvar_init, condvar_notify, condvar_wait, crit_init, crit_enter, crit_exit, crit_terminate
The condvar_wait function is a critical-section function that blocks on a given condition variable. Use this function to wait for a critical section specified by a condition variable argument to become available. The calling thread is blocked until another thread calls condvar_notify with the same condition variable argument. The caller must have entered the critical section associated with this condition variable before calling condvar_wait.
void condvar_wait(CONDVAR cv);
void
CONDVAR cv is a condition variable.
condvar_init, condvar_terminate, condvar_notify, crit_init, crit_enter, crit_exit, crit_terminate
The crit_enter function is a critical-section function that attempts to enter a critical section. Use this function to gain ownership of a critical section. If another thread already owns the section, the calling thread is blocked until the first thread surrenders ownership by calling crit_exit.
void crit_enter(CRITICAL crvar);
void
CRITICAL crvar is a critical-section variable.
crit_init, crit_exit, crit_terminate
The crit_exit function is a critical-section function that surrenders ownership of a critical section. Use this function to surrender ownership of a critical section. If another thread is blocked waiting for the section, the block will be removed and the waiting thread will be given ownership of the section.
void crit_exit(CRITICAL crvar);
void
CRITICAL crvar is a critical-section variable.
crit_init, crit_enter, crit_terminate
The crit_init function is a critical-section function that creates and returns a new critical-section variable (a variable of type CRITICAL). Use this function to obtain a new instance of a variable of type CRITICAL (a critical-section variable) to be used in managing the prevention of interference between two threads of execution. At the time of its creation, no thread owns the critical section.
Threads must not own or be waiting for the critical section when crit_terminate is called.
CRITICAL crit_init(void);
A newly allocated critical-section variable (CRITICAL).
none
crit_enter, crit_exit, crit_terminate
The crit_terminate function is a critical-section function that removes a previously allocated critical-section variable (a variable of type CRITICAL). Use this function to release a critical-section variable previously obtained by a call to crit_init.
void crit_terminate(CRITICAL crvar);
void
CRITICAL crvar is a critical-section variable.