GPAC
Open Source Multimedia Framework. For more information, check out http://gpac.wp.mines-telecom.fr
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups
cache.c File Reference
#include <gpac/cache.h>
#include <gpac/network.h>
#include <gpac/download.h>
#include <gpac/token.h>
#include <gpac/thread.h>
#include <gpac/list.h>
#include <gpac/base_coding.h>
#include <gpac/tools.h>
#include <gpac/config_file.h>
#include <stdio.h>
#include <string.h>
+ Include dependency graph for cache.c:

Data Structures

struct  GF_CacheReader
 
struct  DownloadedRange
 
struct  DownloadedCacheEntry
 

Macros

#define CHECK_ENTRY   if (!entry) { GF_LOG(GF_LOG_WARNING, GF_LOG_NETWORK, ("[CACHE] entry is null at " __FILE__ ":%d\n", __LINE__)); return GF_BAD_PARAM; }
 
#define _CACHE_TMP_SIZE   4096
 
#define _CACHE_HASH_SIZE   20
 
#define _CACHE_MAX_EXTENSION_SIZE   6
 

Enumerations

enum  CacheValid {
  NO_VALIDATION = 0, MUST_REVALIDATE = 1, IS_HTTPS = 2, CORRUPTED = 4,
  NO_CACHE = 8
}
 

Functions

Bool delete_cache_files (void *cbck, char *item_name, char *item_path)
 
GF_Err gf_cache_delete_all_cached_files (const char *directory)
 
void gf_cache_entry_set_delete_files_when_deleted (const DownloadedCacheEntry entry)
 
Bool gf_cache_entry_is_delete_files_when_deleted (const DownloadedCacheEntry entry)
 
const char * gf_cache_get_etag_on_server (const DownloadedCacheEntry entry)
 
const char * gf_cache_get_etag_on_disk (const DownloadedCacheEntry entry)
 
const char * gf_cache_get_mime_type (const DownloadedCacheEntry entry)
 
GF_Err gf_cache_set_etag_on_server (const DownloadedCacheEntry entry, const char *eTag)
 
GF_Err gf_cache_set_etag_on_disk (const DownloadedCacheEntry entry, const char *eTag)
 
GF_Err gf_cache_set_mime_type (const DownloadedCacheEntry entry, const char *mime_type)
 
Bool gf_cache_is_cached_on_disk (const DownloadedCacheEntry entry)
 
u64 gf_cache_get_start_range (const DownloadedCacheEntry entry)
 
u64 gf_cache_get_end_range (const DownloadedCacheEntry entry)
 
const char * gf_cache_get_url (const DownloadedCacheEntry entry)
 
const char * gf_cache_get_hash (const DownloadedCacheEntry entry)
 
const char * gf_cache_get_last_modified_on_server (const DownloadedCacheEntry entry)
 
const char * gf_cache_get_last_modified_on_disk (const DownloadedCacheEntry entry)
 
GF_Err gf_cache_set_last_modified_on_server (const DownloadedCacheEntry entry, const char *newLastModified)
 
GF_Err gf_cache_set_last_modified_on_disk (const DownloadedCacheEntry entry, const char *newLastModified)
 
GF_Err gf_cache_flush_disk_cache (const DownloadedCacheEntry entry)
 
u32 gf_cache_get_cache_filesize (const DownloadedCacheEntry entry)
 
const char * gf_cache_get_cache_filename (const DownloadedCacheEntry entry)
 
GF_Err appendHttpCacheHeaders (const DownloadedCacheEntry entry, char *httpRequest)
 append cache directives to an HTTP GET request More...
 
DownloadedCacheEntry gf_cache_create_entry (GF_DownloadManager *dm, const char *cache_directory, const char *url, u64 start_range, u64 end_range, Bool mem_storage)
 
GF_Err gf_cache_set_content_length (const DownloadedCacheEntry entry, u32 length)
 
u32 gf_cache_get_content_length (const DownloadedCacheEntry entry)
 
GF_Err gf_cache_close_write_cache (const DownloadedCacheEntry entry, const GF_DownloadSession *sess, Bool success)
 Close the write file pointer of cache This function also flushes all buffers, so cache will always be consistent after. More...
 
GF_Err gf_cache_open_write_cache (const DownloadedCacheEntry entry, const GF_DownloadSession *sess)
 Open the write file pointer of cache This function prepares calls for gf_cache_write_to_cache. More...
 
GF_Err gf_cache_write_to_cache (const DownloadedCacheEntry entry, const GF_DownloadSession *sess, const char *data, const u32 size)
 Write data to cache Writes data to the cache. A call to gf_cache_open_write_cache should have been issued before calling this function. More...
 
GF_CacheReader gf_cache_reader_new (const DownloadedCacheEntry entry)
 
GF_Err gf_cache_reader_del (GF_CacheReader handle)
 
s64 gf_cache_reader_seek_at (GF_CacheReader reader, u64 seekPosition)
 
s64 gf_cache_reader_get_position (const GF_CacheReader reader)
 
s64 gf_cache_reader_get_currentSize (GF_CacheReader reader)
 
s64 gf_cache_reader_full_size (GF_CacheReader reader)
 
s32 gf_cache_reader_read (GF_CacheReader reader, char *buff, s32 length)
 
GF_Err gf_cache_delete_entry (const DownloadedCacheEntry entry)
 
Bool gf_cache_check_if_cache_file_is_corrupted (const DownloadedCacheEntry entry)
 
s32 gf_cache_remove_session_from_cache_entry (DownloadedCacheEntry entry, GF_DownloadSession *sess)
 
u32 gf_cache_get_sessions_count_for_cache_entry (const DownloadedCacheEntry entry)
 
s32 gf_cache_add_session_to_cache_entry (DownloadedCacheEntry entry, GF_DownloadSession *sess)
 
FILE * gf_cache_get_file_pointer (const DownloadedCacheEntry entry)
 Returns write file pointer This function returns the current cache file pointer. More...
 
void gf_cache_set_end_range (DownloadedCacheEntry entry, u64 range_end)
 
Bool gf_cache_is_in_progress (const DownloadedCacheEntry entry)
 

Variables

static const char * CACHE_SECTION_NAME = "cache"
 
static const char * CACHE_SECTION_NAME_URL = "url"
 
static const char * CACHE_SECTION_NAME_RANGE = "range"
 
static const char * CACHE_SECTION_NAME_ETAG = "ETag"
 
static const char * CACHE_SECTION_NAME_MIME_TYPE = "Content-Type"
 
static const char * CACHE_SECTION_NAME_CONTENT_SIZE = "Content-Length"
 
static const char * CACHE_SECTION_NAME_LAST_MODIFIED = "Last-Modified"
 
static const char * cache_file_prefix = "gpac_cache_"
 
static const char * default_cache_file_suffix = ".dat"
 
static const char * cache_file_info_suffix = ".txt"
 

Data Structure Documentation

struct __CacheReaderStruct
+ Collaboration diagram for GF_CacheReader:
Data Fields
FILE * readPtr
s64 readPosition
struct __DownloadedRangeStruc
+ Collaboration diagram for DownloadedRange:
Data Fields
u32 start
u32 end
const char * filename
struct __DownloadedCacheEntryStruct

This opaque structure handles the data from the cache

Handle for Cache Entries. You can use the gf_cache_get_* functions to get the cache properties

+ Collaboration diagram for DownloadedCacheEntry:
Data Fields
char * url

URL of the cache (never NULL)

char * hash

Hash of the cache (never NULL)

char * cache_filename

Name of the cache filename, (can be NULL)

GF_Config * properties

Name of the cached properties filename , (can be NULL)

u32 contentLength

Theorical size of cache if any

u32 cacheSize

Real size of cache

u32 validity

GMT timestamp for revalidation

char * serverLastModified

The last modification time on the server

char * diskLastModified

The last modification time of the cache if any

char * serverETag

ETag if any

char * diskETag

ETag if any

char * mimeType

Mime-type (never NULL)

FILE * writeFilePtr

Write pointer for the cache

u32 written_in_cache

Bytes written during this cache session

enum CacheValid flags

Flag indicating whether we have to revalidate

const GF_DownloadSession * write_session
GF_List * sessions
Bool deletableFilesOnDelete
GF_DownloadManager * dm
u64 range_start
u64 range_end
Bool continue_file
Bool file_exists
u32 previousRangeContentLength
Bool memory_stored

Set to 1 if file is not stored on disk

u32 mem_allocated
u8 * mem_storage

Macro Definition Documentation

#define CHECK_ENTRY   if (!entry) { GF_LOG(GF_LOG_WARNING, GF_LOG_NETWORK, ("[CACHE] entry is null at " __FILE__ ":%d\n", __LINE__)); return GF_BAD_PARAM; }
#define _CACHE_TMP_SIZE   4096
#define _CACHE_HASH_SIZE   20
#define _CACHE_MAX_EXTENSION_SIZE   6

Enumeration Type Documentation

enum CacheValid
Enumerator
NO_VALIDATION 
MUST_REVALIDATE 
IS_HTTPS 
CORRUPTED 
NO_CACHE 

Function Documentation

Bool delete_cache_files ( void *  cbck,
char *  item_name,
char *  item_path 
)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool gf_cache_is_cached_on_disk ( const DownloadedCacheEntry  entry)
DownloadedCacheEntry gf_cache_create_entry ( GF_DownloadManager *  dm,
const char *  cache_directory,
const char *  url,
u64  start_range,
u64  end_range,
Bool  mem_storage 
)

Creates a new cache entry

Parameters
dmThe download manager to create this entry
cache_directoryThe path to the directory containing cache files
urlThe full URL
start_rangethe start of the byte range request
end_rangethe end of the byte range request
mem_storageBoolean indicating if the cache data should be stored in memory
Returns
The DownloadedCacheEntry

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GF_Err gf_cache_close_write_cache ( const DownloadedCacheEntry  entry,
const GF_DownloadSession *  sess,
Bool  success 
)
Parameters
entryThe entry to use
sessThe download session
success1 if cache write is success, false otherwise
Returns
GF_OK is everything went fine, GF_BAD_PARAM if entry is NULL, GF_IO_ERR if a failure occurs

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GF_Err gf_cache_open_write_cache ( const DownloadedCacheEntry  entry,
const GF_DownloadSession *  sess 
)
Parameters
entryThe entry to use
sessThe download session
Returns
GF_OK is everything went fine, GF_BAD_PARAM if entry is NULL, GF_IO_ERR if a failure occurs

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GF_Err gf_cache_write_to_cache ( const DownloadedCacheEntry  entry,
const GF_DownloadSession *  sess,
const char *  data,
const u32  size 
)
Parameters
entryThe entry to use
sessThe download session
datadata to write
sizenumber of elements to write
Returns
GF_OK is everything went fine, GF_BAD_PARAM if cache has not been opened, GF_IO_ERR if a failure occurs

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

s64 gf_cache_reader_get_currentSize ( GF_CacheReader  reader)
s64 gf_cache_reader_full_size ( GF_CacheReader  reader)
s32 gf_cache_remove_session_from_cache_entry ( DownloadedCacheEntry  entry,
GF_DownloadSession *  sess 
)

Removes a session for a DownloadedCacheEntry

Parameters
entryThe entry
sessThe session to remove
Returns
the number of sessions left in the cached entry, -1 if one of the parameters is wrong

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

s32 gf_cache_add_session_to_cache_entry ( DownloadedCacheEntry  entry,
GF_DownloadSession *  sess 
)

Adds a session to a DownloadedCacheEntry. implemented in cache.c

Parameters
entryThe entry
sessThe session to add
Returns
the number of sessions in the cached entry, -1 if one of the parameters is wrong

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

FILE* gf_cache_get_file_pointer ( const DownloadedCacheEntry  entry)
Parameters
entryThe entry to use
Returns
cache file pointer or NULL

+ Here is the caller graph for this function:

void gf_cache_set_end_range ( DownloadedCacheEntry  entry,
u64  range_end 
)

+ Here is the caller graph for this function:

Bool gf_cache_is_in_progress ( const DownloadedCacheEntry  entry)

+ Here is the caller graph for this function:

Variable Documentation

const char* CACHE_SECTION_NAME = "cache"
static
const char* CACHE_SECTION_NAME_URL = "url"
static
const char* CACHE_SECTION_NAME_RANGE = "range"
static
const char* CACHE_SECTION_NAME_ETAG = "ETag"
static
const char* CACHE_SECTION_NAME_MIME_TYPE = "Content-Type"
static
const char* CACHE_SECTION_NAME_CONTENT_SIZE = "Content-Length"
static
const char* CACHE_SECTION_NAME_LAST_MODIFIED = "Last-Modified"
static
const char* cache_file_prefix = "gpac_cache_"
static
const char* default_cache_file_suffix = ".dat"
static
const char* cache_file_info_suffix = ".txt"
static